Skip to content

Commit

Permalink
Implemented renaming of symbols and color ramps. Fixes #3509
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15222 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Feb 20, 2011
1 parent 94fd8c3 commit 84bcae0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
12 changes: 10 additions & 2 deletions python/core/symbology-ng-core.sip
Expand Up @@ -886,8 +886,12 @@ public:
//! remove symbol from style (and delete it)
bool removeSymbol(QString name);

//! change symbol's name
//! @note added in v1.7
bool renameSymbol( QString oldName, QString newName );

//! return a NEW copy of symbol
QgsSymbolV2* symbol(QString name);
QgsSymbolV2* symbol(QString name) /Factory/;

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

//! change ramp's name
//! @note added in v1.7
bool renameColorRamp( QString oldName, QString newName );

//! return a NEW copy of color ramp
QgsVectorColorRampV2* colorRamp(QString name);
QgsVectorColorRampV2* colorRamp(QString name) /Factory/;

//! return a const pointer to a symbol (doesn't create new instance)
const QgsVectorColorRampV2* colorRampRef(QString name) const;
Expand Down
18 changes: 18 additions & 0 deletions src/core/symbology-ng/qgsstylev2.cpp
Expand Up @@ -261,3 +261,21 @@ bool QgsStyleV2::save( QString filename )
mFileName = filename;
return true;
}

bool QgsStyleV2::renameSymbol( QString oldName, QString newName )
{
if ( !mSymbols.contains( oldName ) )
return NULL;

mSymbols.insert( newName, mSymbols.take( oldName ) );
return true;
}

bool QgsStyleV2::renameColorRamp( QString oldName, QString newName )
{
if ( !mColorRamps.contains( oldName ) )
return NULL;

mColorRamps.insert( newName, mColorRamps.take( oldName ) );
return true;
}
8 changes: 8 additions & 0 deletions src/core/symbology-ng/qgsstylev2.h
Expand Up @@ -35,6 +35,10 @@ class CORE_EXPORT QgsStyleV2
//! remove symbol from style (and delete it)
bool removeSymbol( QString name );

//! change symbol's name
//! @note added in v1.7
bool renameSymbol( QString oldName, QString newName );

//! return a NEW copy of symbol
QgsSymbolV2* symbol( QString name );

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

//! change ramp's name
//! @note added in v1.7
bool renameColorRamp( QString oldName, QString newName );

//! return a NEW copy of color ramp
QgsVectorColorRampV2* colorRamp( QString name );

Expand Down
28 changes: 27 additions & 1 deletion src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -46,6 +46,8 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
QStandardItemModel* model = new QStandardItemModel( listItems );
listItems->setModel( model );

connect( model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( itemChanged( QStandardItem* ) ) );

populateTypes();

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

// no counting of style items
// no counting of style items
int markerCount = 0, lineCount = 0, fillCount = 0;

QStringList symbolNames = mStyle->symbolNames();
Expand Down Expand Up @@ -130,6 +132,7 @@ void QgsStyleV2ManagerDialog::populateSymbols( int type )
QStandardItem* item = new QStandardItem( name );
QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( symbol, listItems->iconSize() );
item->setIcon( icon );
item->setData( name ); // used to find out original name when user edited the name
// add to model
model->appendRow( item );
}
Expand All @@ -153,6 +156,7 @@ void QgsStyleV2ManagerDialog::populateColorRamps()
QStandardItem* item = new QStandardItem( name );
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, listItems->iconSize() );
item->setIcon( icon );
item->setData( name ); // used to find out original name when user edited the name
model->appendRow( item );
delete ramp;
}
Expand Down Expand Up @@ -453,3 +457,25 @@ bool QgsStyleV2ManagerDialog::removeColorRamp()
mModified = true;
return true;
}

void QgsStyleV2ManagerDialog::itemChanged( QStandardItem* item )
{
// an item has been edited
QString oldName = item->data().toString();

bool changed = false;
if ( currentItemType() < 3 )
{
changed = mStyle->renameSymbol( oldName, item->text() );
}
else if ( currentItemType() == 3 )
{
changed = mStyle->renameColorRamp( oldName, item->text() );
}

if ( changed )
{
populateList();
mModified = true;
}
}
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgsstylev2managerdialog.h
Expand Up @@ -3,6 +3,7 @@
#define QGSSTYLEV2MANAGERDIALOG_H

#include <QDialog>
#include <QStandardItem>

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

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

void itemChanged( QStandardItem* item );

protected:

//! populate combo box with known style items (symbols, color ramps)
Expand Down
3 changes: 3 additions & 0 deletions src/ui/qgssymbolv2propertiesdialogbase.ui
Expand Up @@ -83,6 +83,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item row="2" column="0">
Expand Down

0 comments on commit 84bcae0

Please sign in to comment.