Skip to content
Permalink
Browse files

[FEATURE] Add duplicate button to symbol properties

Allows easy duplication of a symbol layer
  • Loading branch information
nyalldawson committed Jan 6, 2016
1 parent a87646f commit f76babf634bd45a288f3007462afa2ec69321406
@@ -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();
@@ -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" ) ) );

@@ -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();
@@ -362,6 +364,7 @@ void QgsSymbolV2SelectorDialog::updateUi()
btnDown->setEnabled( false );
btnRemoveLayer->setEnabled( false );
btnLock->setEnabled( false );
btnDuplicate->setEnabled( false );
return;
}

@@ -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()
@@ -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;
@@ -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();
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>436</width>
<width>670</width>
<height>359</height>
</rect>
</property>
@@ -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">

0 comments on commit f76babf

Please sign in to comment.
You can’t perform that action at this time.