Skip to content

Commit

Permalink
[FEATURE] Add duplicate button to symbol properties
Browse files Browse the repository at this point in the history
Allows easy duplication of a symbol layer
  • Loading branch information
nyalldawson committed Jan 6, 2016
1 parent a87646f commit f76babf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
4 changes: 4 additions & 0 deletions python/gui/symbology-ng/qgssymbolv2selectordialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class QgsSymbolV2SelectorDialog : QDialog
void saveSymbol();
void lockLayer();

//! Duplicates the current symbol layer and places the duplicated layer above the current symbol layer
//! @note added in QGIS 2.14
void duplicateLayer();

void layerChanged();

void updateLayerPreview();
Expand Down
41 changes: 41 additions & 0 deletions src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsSt
iconLock.addFile( QgsApplication::iconPath( "locked.svg" ), QSize(), QIcon::Normal, QIcon::On );
iconLock.addFile( QgsApplication::iconPath( "unlocked.svg" ), QSize(), QIcon::Normal, QIcon::Off );
btnLock->setIcon( iconLock );
btnDuplicate->setIcon( QIcon( QgsApplication::iconPath( "mActionDuplicateLayer.svg" ) ) );
btnUp->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.svg" ) ) );
btnDown->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.svg" ) ) );

Expand All @@ -259,6 +260,7 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsSt
connect( btnAddLayer, SIGNAL( clicked() ), this, SLOT( addLayer() ) );
connect( btnRemoveLayer, SIGNAL( clicked() ), this, SLOT( removeLayer() ) );
connect( btnLock, SIGNAL( clicked() ), this, SLOT( lockLayer() ) );
connect( btnDuplicate, SIGNAL( clicked() ), this, SLOT( duplicateLayer() ) );
connect( btnSaveSymbol, SIGNAL( clicked() ), this, SLOT( saveSymbol() ) );

updateUi();
Expand Down Expand Up @@ -362,6 +364,7 @@ void QgsSymbolV2SelectorDialog::updateUi()
btnDown->setEnabled( false );
btnRemoveLayer->setEnabled( false );
btnLock->setEnabled( false );
btnDuplicate->setEnabled( false );
return;
}

Expand All @@ -372,6 +375,7 @@ void QgsSymbolV2SelectorDialog::updateUi()
btnDown->setEnabled( currentRow < rowCount - 1 );
btnRemoveLayer->setEnabled( rowCount > 1 );
btnLock->setEnabled( true );
btnDuplicate->setEnabled( true );
}

void QgsSymbolV2SelectorDialog::updatePreview()
Expand Down Expand Up @@ -617,6 +621,43 @@ void QgsSymbolV2SelectorDialog::lockLayer()
layer->setLocked( btnLock->isChecked() );
}

void QgsSymbolV2SelectorDialog::duplicateLayer()
{
QModelIndex idx = layersTree->currentIndex();
if ( !idx.isValid() )
return;

SymbolLayerItem *item = static_cast<SymbolLayerItem*>( model->itemFromIndex( idx ) );
if ( !item->isLayer() )
return;

QgsSymbolLayerV2* source = item->layer();

int insertIdx = item->row();
item = static_cast<SymbolLayerItem*>( item->parent() );

QgsSymbolV2* parentSymbol = item->symbol();

QgsSymbolLayerV2* newLayer = source->clone();
if ( insertIdx == -1 )
parentSymbol->appendSymbolLayer( newLayer );
else
parentSymbol->insertSymbolLayer( item->rowCount() - insertIdx, newLayer );

SymbolLayerItem *newLayerItem = new SymbolLayerItem( newLayer );
item->insertRow( insertIdx == -1 ? 0 : insertIdx, newLayerItem );
if ( newLayer->subSymbol() )
{
loadSymbol( newLayer->subSymbol(), newLayerItem );
layersTree->setExpanded( newLayerItem->index(), true );
}
item->updatePreview();

layersTree->setCurrentIndex( model->indexFromItem( newLayerItem ) );
updateUi();
updatePreview();
}

void QgsSymbolV2SelectorDialog::saveSymbol()
{
bool ok;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/symbology-ng/qgssymbolv2selectordialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class GUI_EXPORT QgsSymbolV2SelectorDialog : public QDialog, private Ui::QgsSymb
void saveSymbol();
void lockLayer();

//! Duplicates the current symbol layer and places the duplicated layer above the current symbol layer
//! @note added in QGIS 2.14
void duplicateLayer();

void layerChanged();

void updateLayerPreview();
Expand Down
18 changes: 17 additions & 1 deletion src/ui/qgssymbolv2selectordialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>436</width>
<width>670</width>
<height>359</height>
</rect>
</property>
Expand Down Expand Up @@ -104,6 +104,22 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnDuplicate">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Duplicates the current layer</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnUp">
<property name="maximumSize">
Expand Down

0 comments on commit f76babf

Please sign in to comment.