Save style file name inside the style.

Fixed saving of symbols added in symbol selector


git-svn-id: http://svn.osgeo.org/qgis/trunk@12161 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2009-11-17 11:23:36 +00:00
parent 1d626d42c3
commit adb8ab92fd
8 changed files with 25 additions and 13 deletions

View File

@ -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();
};
//////////

View File

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

View File

@ -1068,7 +1068,7 @@ void QgisApp::createActions()
void QgisApp::showStyleManagerV2()
{
QgsStyleV2ManagerDialog dlg( QgsStyleV2::defaultStyle(), QgsApplication::userStyleV2Path(), this );
QgsStyleV2ManagerDialog dlg( QgsStyleV2::defaultStyle(), this );
dlg.exec();
}

View File

@ -216,6 +216,7 @@ bool QgsStyleV2::load(QString filename)
e = e.nextSiblingElement();
}
mFileName = filename;
return true;
}
@ -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");
@ -257,5 +258,6 @@ bool QgsStyleV2::save(QString filename)
doc.save(ts, 2);
f.close();
mFileName = filename;
return true;
}

View File

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

View File

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

View File

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

View File

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