Skip to content

Commit

Permalink
Use modal dialog when in properties dialog, allowing to cancel
Browse files Browse the repository at this point in the history
the process and add help button (fix #17903).
Also fix crash that occurs when pressing ESC button.

and fix doc
  • Loading branch information
DelazJ committed Apr 30, 2018
1 parent 89c2b4b commit 1c34339
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ Changes the selected symbols alone for the change button, if there is a selectio
%End

void changeCategorySymbol();
void applyChangeToSymbol();
%Docstring
Applies current symbol to selected categories, or to all categories if none is selected
%End

virtual QList<QgsSymbol *> selectedSymbols();

Expand Down
4 changes: 4 additions & 0 deletions python/gui/symbology/qgsgraduatedsymbolrendererwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ Returns a list of indexes for the classes under selection
void changeRange( int rangeIdx );

void changeSelectedSymbols();
void applyChangeToSymbol();
%Docstring
Applies current symbol to selected ranges, or to all ranges if none is selected
%End

virtual QList<QgsSymbol *> selectedSymbols();

Expand Down
63 changes: 52 additions & 11 deletions src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,32 @@ void QgsCategorizedSymbolRendererWidget::changeSelectedSymbols()

void QgsCategorizedSymbolRendererWidget::changeCategorizedSymbol()
{
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
QgsSymbol *newSymbol = mCategorizedSymbol->clone();
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, nullptr );
dlg->setContext( mContext );
if ( panel && panel->dockMode() )
{
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, panel );
dlg->setContext( mContext );
connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsCategorizedSymbolRendererWidget::cleanUpSymbolSelector );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsCategorizedSymbolRendererWidget::updateCategorizedSymbolIcon );
openPanel( dlg );
}
else
{
QgsSymbolSelectorDialog dlg( newSymbol, mStyle, mLayer, panel );
dlg.setContext( mContext );
if ( !dlg.exec() || !newSymbol )
{
delete newSymbol;
return;
}

connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsCategorizedSymbolRendererWidget::cleanUpSymbolSelector );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsCategorizedSymbolRendererWidget::updateCategorizedSymbolIcon );
openPanel( dlg );
delete mCategorizedSymbol;
mCategorizedSymbol = newSymbol;
updateCategorizedSymbolIcon();
applyChangeToSymbol();
}
}

void QgsCategorizedSymbolRendererWidget::updateCategorizedSymbolIcon()
Expand Down Expand Up @@ -593,11 +611,29 @@ void QgsCategorizedSymbolRendererWidget::changeCategorySymbol()
symbol = QgsSymbol::defaultSymbol( mLayer->geometryType() );
}

QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( symbol, mStyle, mLayer, nullptr );
dlg->setContext( mContext );
connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsCategorizedSymbolRendererWidget::cleanUpSymbolSelector );
openPanel( dlg );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( symbol, mStyle, mLayer, panel );
dlg->setContext( mContext );
connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsCategorizedSymbolRendererWidget::cleanUpSymbolSelector );
openPanel( dlg );
}
else
{
QgsSymbolSelectorDialog dlg( symbol, mStyle, mLayer, panel );
dlg.setContext( mContext );
if ( !dlg.exec() || !symbol )
{
delete symbol;
return;
}

delete mCategorizedSymbol;
mCategorizedSymbol = symbol;
applyChangeToSymbol();
}
}

static void _createCategories( QgsCategoryList &cats, QList<QVariant> &values, QgsSymbol *symbol )
Expand Down Expand Up @@ -954,6 +990,11 @@ void QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget()
QgsSymbolSelectorWidget *dlg = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
mCategorizedSymbol.reset( dlg->symbol()->clone() );

applyChangeToSymbol();
}

void QgsCategorizedSymbolRendererWidget::applyChangeToSymbol()
{
// When there is a selection, change the selected symbols only
QItemSelectionModel *m = viewCategories->selectionModel();
QModelIndexList i = m->selectedRows();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology/qgscategorizedsymbolrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget,
void changeSelectedSymbols();

void changeCategorySymbol();
//! Applies current symbol to selected categories, or to all categories if none is selected
void applyChangeToSymbol();

QList<QgsSymbol *> selectedSymbols() override;
QgsCategoryList selectedCategoryList();
Expand Down
62 changes: 51 additions & 11 deletions src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@ void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
QgsSymbolSelectorWidget *dlg = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
mGraduatedSymbol.reset( dlg->symbol()->clone() );

applyChangeToSymbol();
}

void QgsGraduatedSymbolRendererWidget::applyChangeToSymbol()
{
mSizeUnitWidget->blockSignals( true );
mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
Expand Down Expand Up @@ -874,13 +879,31 @@ void QgsGraduatedSymbolRendererWidget::reapplySizes()
void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
{
QgsSymbol *newSymbol = mGraduatedSymbol->clone();
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, nullptr );
dlg->setContext( mContext );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, panel );
dlg->setContext( mContext );

connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::updateGraduatedSymbolIcon );
panel->openPanel( dlg );
}
else
{
QgsSymbolSelectorDialog dlg( newSymbol, mStyle, mLayer, panel );
if ( !dlg.exec() || !newSymbol )
{
delete newSymbol;
return;
}

connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::updateGraduatedSymbolIcon );
openPanel( dlg );
delete mGraduatedSymbol;
mGraduatedSymbol = newSymbol;
updateGraduatedSymbolIcon();
applyChangeToSymbol();
}
}

void QgsGraduatedSymbolRendererWidget::updateGraduatedSymbolIcon()
Expand Down Expand Up @@ -953,12 +976,29 @@ void QgsGraduatedSymbolRendererWidget::changeSelectedSymbols()
void QgsGraduatedSymbolRendererWidget::changeRangeSymbol( int rangeIdx )
{
QgsSymbol *newSymbol = mRenderer->ranges()[rangeIdx].symbol()->clone();
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, nullptr );
dlg->setContext( mContext );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, panel );
dlg->setContext( mContext );
connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector );
openPanel( dlg );
}
else
{
QgsSymbolSelectorDialog dlg( newSymbol, mStyle, mLayer, panel );
dlg.setContext( mContext );
if ( !dlg.exec() || !newSymbol )
{
delete newSymbol;
return;
}

connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget );
connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector );
openPanel( dlg );
delete mGraduatedSymbol;
mGraduatedSymbol = newSymbol;
applyChangeToSymbol();
}
}

void QgsGraduatedSymbolRendererWidget::changeRange( int rangeIdx )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology/qgsgraduatedsymbolrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, pr
void changeRange( int rangeIdx );

void changeSelectedSymbols();
//! Applies current symbol to selected ranges, or to all ranges if none is selected
void applyChangeToSymbol();

QList<QgsSymbol *> selectedSymbols() override;
QgsSymbol *findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList &ranges ) const;
Expand Down

0 comments on commit 1c34339

Please sign in to comment.