Skip to content

Commit

Permalink
Merge branch 'symbolselectorHelpShow' of https://github.com/DelazJ/QGIS
Browse files Browse the repository at this point in the history
… into DelazJ-symbolselectorHelpShow
  • Loading branch information
elpaso committed May 8, 2018
2 parents ba04dea + 1c34339 commit 85d60f2
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 40 deletions.
10 changes: 7 additions & 3 deletions python/gui/symbology/qgscategorizedsymbolrendererwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,24 @@ from the XML file with a matching name.

int currentCategoryRow();
%Docstring
return row index for the currently selected category (-1 if on no selection)
Returns row index for the currently selected category (-1 if on no selection)
%End

QList<int> selectedCategories();
%Docstring
return a list of indexes for the categories unders selection
Returns a list of indexes for the categories under selection
%End

void changeSelectedSymbols();
%Docstring
change the selected symbols alone for the change button, if there is a selection
Changes the selected symbols alone for the change button, if there is a selection
%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
6 changes: 5 additions & 1 deletion python/gui/symbology/qgsgraduatedsymbolrendererwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ Toggle the link between classes boundaries

QList<int> selectedClasses();
%Docstring
return a list of indexes for the classes under selection
Returns a list of indexes for the classes under selection
%End
QgsRangeList selectedRanges();

void changeRangeSymbol( int rangeIdx );
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
1 change: 1 addition & 0 deletions scripts/spell_check/spelling.dat
Original file line number Diff line number Diff line change
Expand Up @@ -6367,6 +6367,7 @@ skiped:skipped
skiping:skipping
slashs:slashes
slaugterhouses:slaughterhouses
slection:selection
slighly:slightly
sligth:slight
sligthly:slightly
Expand Down
80 changes: 61 additions & 19 deletions src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,17 +544,37 @@ void QgsCategorizedSymbolRendererWidget::changeSelectedSymbols()

void QgsCategorizedSymbolRendererWidget::changeCategorizedSymbol()
{
QgsSymbol *newSymbol = mCategorizedSymbol->clone();
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, nullptr );
dlg->setContext( mContext );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
std::unique_ptr<QgsSymbol> newSymbol( mCategorizedSymbol->clone() );
if ( panel && panel->dockMode() )
{
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol.get(), 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.get(), mStyle, mLayer, panel );
dlg.setContext( mContext );
if ( !dlg.exec() || !newSymbol )
{
return;
}

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

void QgsCategorizedSymbolRendererWidget::updateCategorizedSymbolIcon()
{
if ( !mCategorizedSymbol )
return;

QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mCategorizedSymbol.get(), btnChangeCategorizedSymbol->iconSize() );
btnChangeCategorizedSymbol->setIcon( icon );
}
Expand All @@ -579,21 +599,38 @@ void QgsCategorizedSymbolRendererWidget::changeCategorySymbol()
{
QgsRendererCategory category = mRenderer->categories().value( currentCategoryRow() );

QgsSymbol *symbol = category.symbol();
if ( symbol )
std::unique_ptr< QgsSymbol > symbol;

if ( category.symbol() )
{
symbol = symbol->clone();
symbol.reset( category.symbol()->clone() );
}
else
{
symbol = QgsSymbol::defaultSymbol( mLayer->geometryType() );
symbol.reset( QgsSymbol::defaultSymbol( mLayer->geometryType() ) );
}

QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( symbol.get(), 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.get(), mStyle, mLayer, panel );
dlg.setContext( mContext );
if ( !dlg.exec() || !symbol )
{
return;
}

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 );
mCategorizedSymbol = std::move( symbol );
applyChangeToSymbol();
}
}

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

updateCategorizedSymbolIcon();
applyChangeToSymbol();
}

// When there is a slection, change the selected symbols alone
void QgsCategorizedSymbolRendererWidget::applyChangeToSymbol()
{
// When there is a selection, change the selected symbols only
QItemSelectionModel *m = viewCategories->selectionModel();
QModelIndexList i = m->selectedRows();

Expand All @@ -974,10 +1014,12 @@ void QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget()
}
emit widgetChanged();
}
return;
}
else
{
mRenderer->updateSymbols( mCategorizedSymbol.get() );
}

mRenderer->updateSymbols( mCategorizedSymbol.get() );
emit widgetChanged();
}

Expand Down
8 changes: 5 additions & 3 deletions src/gui/symbology/qgscategorizedsymbolrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,18 @@ class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget,
// Called by virtual refreshSymbolView()
void populateCategories();

//! return row index for the currently selected category (-1 if on no selection)
//! Returns row index for the currently selected category (-1 if on no selection)
int currentCategoryRow();

//! return a list of indexes for the categories unders selection
//! Returns a list of indexes for the categories under selection
QList<int> selectedCategories();

//! change the selected symbols alone for the change button, if there is a selection
//! Changes the selected symbols alone for the change button, if there is a selection
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: 49 additions & 13 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 All @@ -780,7 +785,6 @@ void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
}
else
{
updateGraduatedSymbolIcon();
mRenderer->updateSymbols( mGraduatedSymbol.get() );
}

Expand Down Expand Up @@ -874,13 +878,30 @@ void QgsGraduatedSymbolRendererWidget::reapplySizes()

void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
{
QgsSymbol *newSymbol = mGraduatedSymbol->clone();
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, nullptr );
dlg->setContext( mContext );
std::unique_ptr< QgsSymbol > newSymbol( mGraduatedSymbol->clone() );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol.get(), 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.get(), mStyle, mLayer, panel );
if ( !dlg.exec() || !newSymbol )
{
return;
}

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

void QgsGraduatedSymbolRendererWidget::updateGraduatedSymbolIcon()
Expand Down Expand Up @@ -952,13 +973,28 @@ 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 );
std::unique_ptr< QgsSymbol > newSymbol( mRenderer->ranges()[rangeIdx].symbol()->clone() );
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol.get(), 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.get(), mStyle, mLayer, panel );
dlg.setContext( mContext );
if ( !dlg.exec() || !newSymbol )
{
return;
}

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

void QgsGraduatedSymbolRendererWidget::changeRange( int rangeIdx )
Expand Down
4 changes: 3 additions & 1 deletion src/gui/symbology/qgsgraduatedsymbolrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,16 @@ class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, pr

void updateGraduatedSymbolIcon();

//! return a list of indexes for the classes under selection
//! Returns a list of indexes for the classes under selection
QList<int> selectedClasses();
QgsRangeList selectedRanges();

void changeRangeSymbol( int rangeIdx );
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 85d60f2

Please sign in to comment.