Skip to content

Commit

Permalink
[composer] Port remaining symbol pickers to inline panels
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 11, 2016
1 parent c36c242 commit 44546e8
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 55 deletions.
11 changes: 7 additions & 4 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -575,6 +575,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mGeneralDock = new QgsDockWidget( tr( "Composition" ), this );
mGeneralDock->setObjectName( "CompositionDock" );
mGeneralDock->setMinimumWidth( minDockWidth );
mGeneralPropertiesStack = new QgsPanelWidgetStack();
mGeneralDock->setWidget( mGeneralPropertiesStack );
mPanelMenu->addAction( mGeneralDock->toggleViewAction() );
mItemDock = new QgsDockWidget( tr( "Item properties" ), this );
mItemDock->setObjectName( "ItemDock" );
Expand Down Expand Up @@ -925,7 +927,7 @@ bool QgsComposer::loadFromTemplate( const QDomDocument& templateDoc, bool clearE
if ( result )
{
// update composition widget
QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mGeneralDock->widget() );
QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mGeneralPropertiesStack->takeMainPanel() );
delete oldCompositionWidget;
createCompositionWidget();
}
Expand Down Expand Up @@ -1548,7 +1550,7 @@ void QgsComposer::setComposition( QgsComposition* composition )
}

//delete composition widget
QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mGeneralDock->widget() );
QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mGeneralPropertiesStack->takeMainPanel() );
delete oldCompositionWidget;

deleteItemWidgets();
Expand Down Expand Up @@ -3514,10 +3516,11 @@ void QgsComposer::createCompositionWidget()
}

QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mGeneralDock, mComposition );
compositionWidget->setDockMode( true );
connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
connect( this, SIGNAL( printAsRasterChanged( bool ) ), compositionWidget, SLOT( setPrintAsRasterCheckBox( bool ) ) );
connect( compositionWidget, SIGNAL( pageOrientationChanged( QString ) ), this, SLOT( pageOrientationChanged( QString ) ) );
mGeneralDock->setWidget( compositionWidget );
mGeneralPropertiesStack->setMainPanel( compositionWidget );
}

void QgsComposer::readXml( const QDomElement& composerElem, const QDomDocument& doc, bool fromTemplate )
Expand All @@ -3532,7 +3535,7 @@ void QgsComposer::readXml( const QDomElement& composerElem, const QDomDocument&
}

//delete composition widget
QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mGeneralDock->widget() );
QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mGeneralPropertiesStack->takeMainPanel() );
delete oldCompositionWidget;

deleteItemWidgets();
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscomposer.h
Expand Up @@ -602,6 +602,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
QgsPanelWidgetStack* mItemPropertiesStack;
QgsDockWidget* mUndoDock;
QgsDockWidget* mGeneralDock;
QgsPanelWidgetStack* mGeneralPropertiesStack;
QgsDockWidget* mAtlasDock;
QgsDockWidget* mItemsDock;

Expand Down
42 changes: 28 additions & 14 deletions src/app/composer/qgscomposerarrowwidget.cpp
Expand Up @@ -169,6 +169,24 @@ void QgsComposerArrowWidget::setGuiElementValues()
blockAllSignals( false );
}

void QgsComposerArrowWidget::updateLineStyleFromWidget()
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
mArrow->setLineSymbol( dynamic_cast< QgsLineSymbol* >( w->symbol()->clone() ) );
mArrow->update();
}

void QgsComposerArrowWidget::cleanUpLineStyleSelector( QgsPanelWidget* container )
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( container );
if ( !w )
return;

delete w->symbol();
updateLineSymbolMarker();
mArrow->endCommand();
}

void QgsComposerArrowWidget::enableSvgInputElements( bool enable )
{
mStartMarkerLineEdit->setEnabled( enable );
Expand Down Expand Up @@ -310,25 +328,21 @@ void QgsComposerArrowWidget::on_mLineStyleButton_clicked()
return;
}

// use the atlas coverage layer, if any
QgsVectorLayer* coverageLayer = atlasCoverageLayer();

QgsLineSymbol* newSymbol = mArrow->lineSymbol()->clone();
QgsSymbolSelectorDialog d( newSymbol, QgsStyle::defaultStyle(), nullptr, this );
QgsExpressionContext context = mArrow->createExpressionContext();

QgsSymbolSelectorWidget* d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), coverageLayer, nullptr );
QgsSymbolWidgetContext symbolContext;
symbolContext.setExpressionContext( &context );
d.setContext( symbolContext );
d->setContext( symbolContext );

if ( d.exec() == QDialog::Accepted )
{
mArrow->beginCommand( tr( "Arrow line style changed" ) );
mArrow->setLineSymbol( newSymbol );
updateLineSymbolMarker();
mArrow->endCommand();
mArrow->update();
}
else
{
delete newSymbol;
}
connect( d, SIGNAL( widgetChanged() ), this, SLOT( updateLineStyleFromWidget() ) );
connect( d, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpLineStyleSelector( QgsPanelWidget* ) ) );
openPanel( d );
mArrow->beginCommand( tr( "Arrow line style changed" ) );
}

void QgsComposerArrowWidget::updateLineSymbolMarker()
Expand Down
3 changes: 3 additions & 0 deletions src/app/composer/qgscomposerarrowwidget.h
Expand Up @@ -57,6 +57,9 @@ class QgsComposerArrowWidget: public QgsComposerItemBaseWidget, private Ui::QgsC
void on_mLineStyleButton_clicked();

void setGuiElementValues();

void updateLineStyleFromWidget();
void cleanUpLineStyleSelector( QgsPanelWidget* container );
};

#endif // QGSCOMPOSERARROWWIDGET_H
41 changes: 27 additions & 14 deletions src/app/composer/qgscomposerpolygonwidget.cpp
Expand Up @@ -31,7 +31,7 @@ QgsComposerPolygonWidget::QgsComposerPolygonWidget( QgsComposerPolygon* composer
//add widget for general composer item properties
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, composerPolygon );

//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorDialog
//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
itemPropertiesWidget->showBackgroundGroup( false );
itemPropertiesWidget->showFrameGroup( false );
mainLayout->addWidget( itemPropertiesWidget );
Expand Down Expand Up @@ -59,23 +59,18 @@ void QgsComposerPolygonWidget::on_mPolygonStyleButton_clicked()
// use the atlas coverage layer, if any
QgsVectorLayer* coverageLayer = atlasCoverageLayer();

QScopedPointer<QgsFillSymbol> newSymbol;
newSymbol.reset( mComposerPolygon->polygonStyleSymbol()->clone() );

QgsFillSymbol* newSymbol = mComposerPolygon->polygonStyleSymbol()->clone();
QgsExpressionContext context = mComposerPolygon->createExpressionContext();
QgsSymbolSelectorDialog d( newSymbol.data(), QgsStyle::defaultStyle(),
coverageLayer, this );

QgsSymbolSelectorWidget* d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), coverageLayer, nullptr );
QgsSymbolWidgetContext symbolContext;
symbolContext.setExpressionContext( &context );
d.setContext( symbolContext );
d->setContext( symbolContext );

if ( d.exec() == QDialog::Accepted )
{
mComposerPolygon->beginCommand( tr( "Polygon style changed" ) );
mComposerPolygon->setPolygonStyleSymbol( newSymbol.data() );
updatePolygonStyle();
mComposerPolygon->endCommand();
}
connect( d, SIGNAL( widgetChanged() ), this, SLOT( updateStyleFromWidget() ) );
connect( d, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpStyleSelector( QgsPanelWidget* ) ) );
openPanel( d );
mComposerPolygon->beginCommand( tr( "Polygon style changed" ) );
}

void QgsComposerPolygonWidget::setGuiElementValues()
Expand All @@ -88,6 +83,24 @@ void QgsComposerPolygonWidget::setGuiElementValues()
updatePolygonStyle();
}

void QgsComposerPolygonWidget::updateStyleFromWidget()
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
mComposerPolygon->setPolygonStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
mComposerPolygon->update();
}

void QgsComposerPolygonWidget::cleanUpStyleSelector( QgsPanelWidget* container )
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( container );
if ( !w )
return;

delete w->symbol();
updatePolygonStyle();
mComposerPolygon->endCommand();
}

void QgsComposerPolygonWidget::updatePolygonStyle()
{
if ( mComposerPolygon )
Expand Down
3 changes: 3 additions & 0 deletions src/app/composer/qgscomposerpolygonwidget.h
Expand Up @@ -43,6 +43,9 @@ class QgsComposerPolygonWidget: public QgsComposerItemBaseWidget, private Ui::Qg

/** Sets the GUI elements to the currentValues of mComposerShape*/
void setGuiElementValues();

void updateStyleFromWidget();
void cleanUpStyleSelector( QgsPanelWidget* container );
};

#endif // QGSCOMPOSERPOLYGONWIDGET_H
40 changes: 28 additions & 12 deletions src/app/composer/qgscomposerpolylinewidget.cpp
Expand Up @@ -51,23 +51,21 @@ void QgsComposerPolylineWidget::on_mLineStyleButton_clicked()
if ( !mComposerPolyline )
return;

QScopedPointer<QgsLineSymbol> newSymbol;
newSymbol.reset( mComposerPolyline->polylineStyleSymbol()->clone() );
// use the atlas coverage layer, if any
QgsVectorLayer* coverageLayer = atlasCoverageLayer();

QgsLineSymbol* newSymbol = mComposerPolyline->polylineStyleSymbol()->clone();
QgsExpressionContext context = mComposerPolyline->createExpressionContext();
QgsSymbolSelectorDialog d( newSymbol.data(), QgsStyle::defaultStyle(),
nullptr, this );

QgsSymbolSelectorWidget* d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), coverageLayer, nullptr );
QgsSymbolWidgetContext symbolContext;
symbolContext.setExpressionContext( &context );
d.setContext( symbolContext );
d->setContext( symbolContext );

if ( d.exec() == QDialog::Accepted )
{
mComposerPolyline->beginCommand( tr( "Polyline style changed" ) );
mComposerPolyline->setPolylineStyleSymbol( newSymbol.data() );
updatePolylineStyle();
mComposerPolyline->endCommand();
}
connect( d, SIGNAL( widgetChanged() ), this, SLOT( updateStyleFromWidget() ) );
connect( d, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpStyleSelector( QgsPanelWidget* ) ) );
openPanel( d );
mComposerPolyline->beginCommand( tr( "Polyline style changed" ) );
}

void QgsComposerPolylineWidget::setGuiElementValues()
Expand All @@ -78,6 +76,24 @@ void QgsComposerPolylineWidget::setGuiElementValues()
updatePolylineStyle();
}

void QgsComposerPolylineWidget::updateStyleFromWidget()
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
mComposerPolyline->setPolylineStyleSymbol( dynamic_cast< QgsLineSymbol* >( w->symbol() ) );
mComposerPolyline->update();
}

void QgsComposerPolylineWidget::cleanUpStyleSelector( QgsPanelWidget* container )
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( container );
if ( !w )
return;

delete w->symbol();
updatePolylineStyle();
mComposerPolyline->endCommand();
}

void QgsComposerPolylineWidget::updatePolylineStyle()
{
if ( mComposerPolyline )
Expand Down
3 changes: 3 additions & 0 deletions src/app/composer/qgscomposerpolylinewidget.h
Expand Up @@ -43,6 +43,9 @@ class QgsComposerPolylineWidget: public QgsComposerItemBaseWidget, private Ui::Q

/** Sets the GUI elements to the currentValues of mComposerShape*/
void setGuiElementValues();

void updateStyleFromWidget();
void cleanUpStyleSelector( QgsPanelWidget* container );
};

#endif // QGSCOMPOSERPOLYLINEWIDGET_H
41 changes: 31 additions & 10 deletions src/app/composer/qgscompositionwidget.cpp
Expand Up @@ -28,9 +28,13 @@
#include <QWidget>
#include <QPrinter> //for screen resolution

QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c ): QWidget( parent ), mComposition( c )
QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )\
:
QgsPanelWidget( parent )
, mComposition( c )
{
setupUi( this );
setPanelTitle( tr( "Composition properties" ) );
blockSignals( true );
createPaperEntries();

Expand Down Expand Up @@ -133,7 +137,9 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
blockSignals( false );
}

QgsCompositionWidget::QgsCompositionWidget(): QWidget( nullptr ), mComposition( nullptr )
QgsCompositionWidget::QgsCompositionWidget()
: QgsPanelWidget( nullptr )
, mComposition( nullptr )
{
setupUi( this );
}
Expand Down Expand Up @@ -247,6 +253,23 @@ QgsComposerObject::DataDefinedProperty QgsCompositionWidget::ddPropertyForWidget
return QgsComposerObject::NoProperty;
}

void QgsCompositionWidget::updateStyleFromWidget()
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( sender() );
mComposition->setPageStyleSymbol( dynamic_cast< QgsFillSymbol* >( w->symbol() ) );
mComposition->update();
}

void QgsCompositionWidget::cleanUpStyleSelector( QgsPanelWidget* container )
{
QgsSymbolSelectorWidget* w = qobject_cast<QgsSymbolSelectorWidget*>( container );
if ( !w )
return;

delete w->symbol();
updatePageStyle();
}

void QgsCompositionWidget::updateDataDefinedProperty()
{
QgsDataDefinedButton* ddButton = dynamic_cast<QgsDataDefinedButton*>( sender() );
Expand Down Expand Up @@ -572,17 +595,15 @@ void QgsCompositionWidget::on_mPageStyleButton_clicked()
newSymbol = new QgsFillSymbol();
}
QgsExpressionContext context = mComposition->createExpressionContext();
QgsSymbolSelectorDialog d( newSymbol, QgsStyle::defaultStyle(), coverageLayer, this );

QgsSymbolSelectorWidget* d = new QgsSymbolSelectorWidget( newSymbol, QgsStyle::defaultStyle(), coverageLayer, nullptr );
QgsSymbolWidgetContext symbolContext;
symbolContext.setExpressionContext( &context );
d.setContext( symbolContext );
d->setContext( symbolContext );

if ( d.exec() == QDialog::Accepted )
{
mComposition->setPageStyleSymbol( newSymbol );
updatePageStyle();
}
delete newSymbol;
connect( d, SIGNAL( widgetChanged() ), this, SLOT( updateStyleFromWidget() ) );
connect( d, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpStyleSelector( QgsPanelWidget* ) ) );
openPanel( d );
}

void QgsCompositionWidget::on_mResizePageButton_clicked()
Expand Down
7 changes: 6 additions & 1 deletion src/app/composer/qgscompositionwidget.h
Expand Up @@ -15,6 +15,7 @@
***************************************************************************/

#include "ui_qgscompositionwidgetbase.h"
#include "qgspanelwidget.h"

class QgsComposition;
class QgsComposerMap;
Expand All @@ -34,7 +35,7 @@ struct QgsCompositionPaper
/** \ingroup app
* Input widget for QgsComposition
*/
class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
class QgsCompositionWidget: public QgsPanelWidget, private Ui::QgsCompositionWidgetBase
{
Q_OBJECT
public:
Expand Down Expand Up @@ -85,6 +86,9 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase

void updateVariables();

void updateStyleFromWidget();
void cleanUpStyleSelector( QgsPanelWidget* container );

private:
QgsComposition* mComposition;
QMap<QString, QgsCompositionPaper> mPaperMap;
Expand Down Expand Up @@ -115,4 +119,5 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
/** Returns the data defined property corresponding to a data defined button widget*/
virtual QgsComposerObject::DataDefinedProperty ddPropertyForWidget( QgsDataDefinedButton* widget );


};

0 comments on commit 44546e8

Please sign in to comment.