Skip to content

Commit

Permalink
Save style file name inside the style.
Browse files Browse the repository at this point in the history
Fixed saving of symbols added in symbol selector


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12161 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Nov 17, 2009
1 parent 25b2f95 commit 1a5cc6c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
8 changes: 6 additions & 2 deletions python/core/symbology-ng-core.sip
Expand Up @@ -670,11 +670,15 @@ public:
//! load a file into the style
bool load(QString filename);

//! save style into a file
bool save(QString filename);
//! save style into a file (will use current filename if empty string is passed)
bool save(QString filename = QString());

//! return last error from load/save operation
QString errorString();

//! return current file name of the style
QString fileName();

};

//////////
Expand Down
2 changes: 1 addition & 1 deletion python/gui/symbology-ng-gui.sip
Expand Up @@ -59,7 +59,7 @@ class QgsStyleV2ManagerDialog : QDialog //, private Ui::QgsStyleV2ManagerDialogB
%End

public:
QgsStyleV2ManagerDialog(QgsStyleV2* style, QString styleFilename, QWidget* parent = NULL);
QgsStyleV2ManagerDialog(QgsStyleV2* style, QWidget* parent = NULL);

public slots:
void addItem();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -1068,7 +1068,7 @@ void QgisApp::createActions()

void QgisApp::showStyleManagerV2()
{
QgsStyleV2ManagerDialog dlg( QgsStyleV2::defaultStyle(), QgsApplication::userStyleV2Path(), this );
QgsStyleV2ManagerDialog dlg( QgsStyleV2::defaultStyle(), this );
dlg.exec();
}

Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology-ng/qgsstylev2.cpp
Expand Up @@ -216,6 +216,7 @@ bool QgsStyleV2::load(QString filename)
e = e.nextSiblingElement();
}

mFileName = filename;
return true;
}

Expand All @@ -224,8 +225,8 @@ bool QgsStyleV2::load(QString filename)
bool QgsStyleV2::save(QString filename)
{
mErrorString = QString();
//if (filename.isEmpty())
// filename = mFilename;
if (filename.isEmpty())
filename = mFileName;

QDomDocument doc("qgis_style");
QDomElement root = doc.createElement("qgis_style");
Expand Down Expand Up @@ -257,5 +258,6 @@ bool QgsStyleV2::save(QString filename)
doc.save(ts, 2);
f.close();

mFileName = filename;
return true;
}
8 changes: 6 additions & 2 deletions src/core/symbology-ng/qgsstylev2.h
Expand Up @@ -70,18 +70,22 @@ class CORE_EXPORT QgsStyleV2
//! load a file into the style
bool load( QString filename );

//! save style into a file
bool save( QString filename );
//! save style into a file (will use current filename if empty string is passed)
bool save( QString filename = QString() );

//! return last error from load/save operation
QString errorString() { return mErrorString; }

//! return current file name of the style
QString fileName() { return mFileName; }

protected:

QgsSymbolV2Map mSymbols;
QgsVectorColorRampV2Map mColorRamps;

QString mErrorString;
QString mFileName;

static QgsStyleV2* mDefaultStyle;
};
Expand Down
7 changes: 3 additions & 4 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -32,8 +32,8 @@ static QString iconPath( QString iconFile )

///////

QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QString styleFilename, QWidget* parent )
: QDialog( parent ), mStyle( style ), mStyleFilename( styleFilename )
QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* parent )
: QDialog( parent ), mStyle( style )
{

setupUi( this );
Expand Down Expand Up @@ -65,8 +65,7 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QString sty
void QgsStyleV2ManagerDialog::onFinished()
{
// TODO: save only when modified
if ( !mStyleFilename.isEmpty() )
mStyle->save( mStyleFilename );
mStyle->save();
}

void QgsStyleV2ManagerDialog::populateTypes()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology-ng/qgsstylev2managerdialog.h
Expand Up @@ -13,7 +13,7 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
Q_OBJECT

public:
QgsStyleV2ManagerDialog( QgsStyleV2* style, QString styleFilename, QWidget* parent = NULL );
QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* parent = NULL );

public slots:
void addItem();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
Expand Up @@ -206,6 +206,9 @@ void QgsSymbolV2SelectorDialog::addSymbolToStyle()
// add new symbol to style and re-populate the list
mStyle->addSymbol(name, mSymbol->clone());

// make sure the symbol is stored
mStyle->save();

populateSymbolView();
}

Expand Down

0 comments on commit 1a5cc6c

Please sign in to comment.