Skip to content
Permalink
Browse files
Implemented renaming of symbols and color ramps. Fixes #3509
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 84bcae0d128b66179dc64b07d52878578d18c134
@@ -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;
@@ -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;
@@ -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;
}
@@ -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 );

@@ -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 );

@@ -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() ) );
@@ -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();
@@ -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 );
}
@@ -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;
}
@@ -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,6 +3,7 @@
#define QGSSTYLEV2MANAGERDIALOG_H

#include <QDialog>
#include <QStandardItem>

#include "ui_qgsstylev2managerdialogbase.h"
#include "qgscontexthelp.h"
@@ -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)
@@ -83,6 +83,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item row="2" column="0">

0 comments on commit 84bcae0

Please sign in to comment.