Skip to content

Commit 4f82c34

Browse files
author
wonder
committed
Implemented renaming of symbols and color ramps. Fixes #3509
git-svn-id: http://svn.osgeo.org/qgis/trunk@15222 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5c1302f commit 4f82c34

File tree

6 files changed

+69
-3
lines changed

6 files changed

+69
-3
lines changed

python/core/symbology-ng-core.sip

+10-2
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,12 @@ public:
886886
//! remove symbol from style (and delete it)
887887
bool removeSymbol(QString name);
888888

889+
//! change symbol's name
890+
//! @note added in v1.7
891+
bool renameSymbol( QString oldName, QString newName );
892+
889893
//! return a NEW copy of symbol
890-
QgsSymbolV2* symbol(QString name);
894+
QgsSymbolV2* symbol(QString name) /Factory/;
891895

892896
//! return a const pointer to a symbol (doesn't create new instance)
893897
const QgsSymbolV2* symbolRef(QString name) const;
@@ -905,8 +909,12 @@ public:
905909
//! remove color ramp from style (and delete it)
906910
bool removeColorRamp(QString name);
907911

912+
//! change ramp's name
913+
//! @note added in v1.7
914+
bool renameColorRamp( QString oldName, QString newName );
915+
908916
//! return a NEW copy of color ramp
909-
QgsVectorColorRampV2* colorRamp(QString name);
917+
QgsVectorColorRampV2* colorRamp(QString name) /Factory/;
910918

911919
//! return a const pointer to a symbol (doesn't create new instance)
912920
const QgsVectorColorRampV2* colorRampRef(QString name) const;

src/core/symbology-ng/qgsstylev2.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,21 @@ bool QgsStyleV2::save( QString filename )
261261
mFileName = filename;
262262
return true;
263263
}
264+
265+
bool QgsStyleV2::renameSymbol( QString oldName, QString newName )
266+
{
267+
if ( !mSymbols.contains( oldName ) )
268+
return NULL;
269+
270+
mSymbols.insert( newName, mSymbols.take( oldName ) );
271+
return true;
272+
}
273+
274+
bool QgsStyleV2::renameColorRamp( QString oldName, QString newName )
275+
{
276+
if ( !mColorRamps.contains( oldName ) )
277+
return NULL;
278+
279+
mColorRamps.insert( newName, mColorRamps.take( oldName ) );
280+
return true;
281+
}

src/core/symbology-ng/qgsstylev2.h

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class CORE_EXPORT QgsStyleV2
3535
//! remove symbol from style (and delete it)
3636
bool removeSymbol( QString name );
3737

38+
//! change symbol's name
39+
//! @note added in v1.7
40+
bool renameSymbol( QString oldName, QString newName );
41+
3842
//! return a NEW copy of symbol
3943
QgsSymbolV2* symbol( QString name );
4044

@@ -54,6 +58,10 @@ class CORE_EXPORT QgsStyleV2
5458
//! remove color ramp from style (and delete it)
5559
bool removeColorRamp( QString name );
5660

61+
//! change ramp's name
62+
//! @note added in v1.7
63+
bool renameColorRamp( QString oldName, QString newName );
64+
5765
//! return a NEW copy of color ramp
5866
QgsVectorColorRampV2* colorRamp( QString name );
5967

src/gui/symbology-ng/qgsstylev2managerdialog.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
4646
QStandardItemModel* model = new QStandardItemModel( listItems );
4747
listItems->setModel( model );
4848

49+
connect( model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( itemChanged( QStandardItem* ) ) );
50+
4951
populateTypes();
5052

5153
connect( tabItemType, SIGNAL( currentChanged( int ) ), this, SLOT( populateList() ) );
@@ -68,7 +70,7 @@ void QgsStyleV2ManagerDialog::populateTypes()
6870
// save current selection index in types combo
6971
int current = ( tabItemType->count() > 0 ? tabItemType->currentIndex() : 0 );
7072

71-
// no counting of style items
73+
// no counting of style items
7274
int markerCount = 0, lineCount = 0, fillCount = 0;
7375

7476
QStringList symbolNames = mStyle->symbolNames();
@@ -130,6 +132,7 @@ void QgsStyleV2ManagerDialog::populateSymbols( int type )
130132
QStandardItem* item = new QStandardItem( name );
131133
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( symbol, listItems->iconSize() );
132134
item->setIcon( icon );
135+
item->setData( name ); // used to find out original name when user edited the name
133136
// add to model
134137
model->appendRow( item );
135138
}
@@ -153,6 +156,7 @@ void QgsStyleV2ManagerDialog::populateColorRamps()
153156
QStandardItem* item = new QStandardItem( name );
154157
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, listItems->iconSize() );
155158
item->setIcon( icon );
159+
item->setData( name ); // used to find out original name when user edited the name
156160
model->appendRow( item );
157161
delete ramp;
158162
}
@@ -453,3 +457,25 @@ bool QgsStyleV2ManagerDialog::removeColorRamp()
453457
mModified = true;
454458
return true;
455459
}
460+
461+
void QgsStyleV2ManagerDialog::itemChanged( QStandardItem* item )
462+
{
463+
// an item has been edited
464+
QString oldName = item->data().toString();
465+
466+
bool changed = false;
467+
if ( currentItemType() < 3 )
468+
{
469+
changed = mStyle->renameSymbol( oldName, item->text() );
470+
}
471+
else if ( currentItemType() == 3 )
472+
{
473+
changed = mStyle->renameColorRamp( oldName, item->text() );
474+
}
475+
476+
if ( changed )
477+
{
478+
populateList();
479+
mModified = true;
480+
}
481+
}

src/gui/symbology-ng/qgsstylev2managerdialog.h

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define QGSSTYLEV2MANAGERDIALOG_H
44

55
#include <QDialog>
6+
#include <QStandardItem>
67

78
#include "ui_qgsstylev2managerdialogbase.h"
89
#include "qgscontexthelp.h"
@@ -31,6 +32,8 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
3132

3233
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
3334

35+
void itemChanged( QStandardItem* item );
36+
3437
protected:
3538

3639
//! populate combo box with known style items (symbols, color ramps)

src/ui/qgssymbolv2propertiesdialogbase.ui

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
<verstretch>0</verstretch>
8484
</sizepolicy>
8585
</property>
86+
<property name="editTriggers">
87+
<set>QAbstractItemView::NoEditTriggers</set>
88+
</property>
8689
</widget>
8790
</item>
8891
<item row="2" column="0">

0 commit comments

Comments
 (0)