Skip to content

Commit 21253f9

Browse files
committed
[FEATURE] Reworked symbol selector/properties dialog, greatly improved style manager
This is merge of Arun's GSoC 2012 work. Merge remote-tracking branch 'arun/gsoc' Conflicts: src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
2 parents da5609c + d2f08ee commit 21253f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5038
-1941
lines changed

python/core/symbology-ng-core.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ class QgsSymbolLayerV2Utils
12651265

12661266
static QgsSymbolV2* loadSymbol( QDomElement& element ) /Factory/;
12671267
static QgsSymbolLayerV2* loadSymbolLayer( QDomElement& element ) /Factory/;
1268-
static QDomElement saveSymbol( QString name, QgsSymbolV2* symbol, QDomDocument& doc, QgsSymbolV2Map* subSymbols = NULL );
1268+
static QDomElement saveSymbol( QString name, QgsSymbolV2* symbol, QDomDocument& doc );
12691269

12701270
static QgsStringMap parseProperties( QDomElement& element );
12711271
static void saveProperties( QgsStringMap props, QDomDocument& doc, QDomElement& element );

python/gui/symbology-ng-gui.sip

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11

2-
3-
class QgsSymbolV2PropertiesDialog : QDialog //, private Ui::DlgSymbolV2Properties
4-
{
5-
%TypeHeaderCode
6-
#include <qgssymbolv2propertiesdialog.h>
7-
%End
8-
9-
public:
10-
QgsSymbolV2PropertiesDialog(QgsSymbolV2* symbol, const QgsVectorLayer* vl, QWidget* parent = NULL);
11-
12-
13-
public slots:
14-
void moveLayerDown();
15-
void moveLayerUp();
16-
17-
void addLayer();
18-
void removeLayer();
19-
20-
void lockLayer();
21-
22-
void layerTypeChanged();
23-
24-
void layerChanged();
25-
26-
};
27-
28-
292
class QgsRendererV2PropertiesDialog : QDialog //, private Ui::QgsRendererV2PropsDialogBase
303
{
314
%TypeHeaderCode
@@ -71,27 +44,33 @@ class QgsSymbolV2SelectorDialog : QDialog //, private Ui::QgsSymbolV2SelectorDia
7144
%TypeHeaderCode
7245
#include <qgssymbolv2selectordialog.h>
7346
%End
47+
public:
48+
QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsStyleV2* style, const QgsVectorLayer* vl, QWidget* parent = NULL, bool embedded = false );
7449

75-
public:
76-
QgsSymbolV2SelectorDialog(QgsSymbolV2* symbol, QgsStyleV2* style, const QgsVectorLayer* vl, QWidget* parent = NULL, bool embedded = false);
77-
78-
protected:
79-
void populateSymbolView();
80-
void updateSymbolPreview();
81-
void updateSymbolColor();
82-
void updateSymbolInfo();
83-
50+
QMenu* advancedMenu();
8451

85-
public slots:
86-
void changeSymbolProperties();
87-
void setSymbolFromStyle(const QModelIndex & index);
88-
void setSymbolColor();
89-
void setMarkerAngle(double angle);
90-
void setMarkerSize(double size);
91-
void setLineWidth(double width);
92-
93-
signals:
94-
void symbolModified();
52+
protected:
53+
void keyPressEvent( QKeyEvent * event );
54+
55+
void loadSymbol();
56+
void updateUi();
57+
void updateLockButton();
58+
QgsSymbolLayerV2* currentLayer();
59+
void moveLayerByOffset( int offset );
60+
void setWidget( QWidget* widget );
61+
62+
signals:
63+
void symbolModified();
64+
65+
public slots:
66+
void moveLayerDown();
67+
void moveLayerUp();
68+
void addLayer();
69+
void removeLayer();
70+
void lockLayer();
71+
void layerChanged();
72+
void updateLayerPreview();
73+
void updatePreview();
9574

9675
};
9776

resources/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
INSTALL(FILES srs.db qgis.db qgis_help.db symbology-ng-style.xml spatialite.db customization.xml
1+
INSTALL(FILES srs.db qgis.db qgis_help.db symbology-ng-style.db spatialite.db customization.xml
22
DESTINATION ${QGIS_DATA_DIR}/resources)
33

44
ADD_SUBDIRECTORY(context_help)

resources/symbology-ng-style.db

49 KB
Binary file not shown.

scripts/symbol_xml2db.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/python
2+
"""
3+
/***************************************************************************
4+
symbol_xml2db.py
5+
-------------------
6+
begin : 26-5-2012
7+
copyright : (C) 2012 by Arunmozhi
8+
email : aruntheguy at gmail dot com
9+
***************************************************************************/
10+
11+
/***************************************************************************
12+
* *
13+
* This program is free software; you can redistribute it and/or modify *
14+
* it under the terms of the GNU General Public License as published by *
15+
* the Free Software Foundation; either version 2 of the License, or *
16+
* (at your option) any later version. *
17+
* *
18+
***************************************************************************/
19+
20+
The script creates a sqlite3 Db for storing the symbols which will be
21+
shipped with QGIS by default. It then converts symbols and colorramps
22+
in the symbology_ng_style.xml to the database table entries.
23+
"""
24+
import sqlite3
25+
26+
from xml.dom.minidom import parse, parseString
27+
28+
xmlfile = "../resources/symbology-ng-style.xml"
29+
dbfile = "../resources/symbology-ng-style.db"
30+
31+
_symbol = "CREATE TABLE symbol("\
32+
"id INTEGER PRIMARY KEY,"\
33+
"name TEXT UNIQUE,"\
34+
"xml TEXT,"\
35+
"groupid INTEGER)"
36+
37+
_colorramp = "CREATE TABLE colorramp("\
38+
"id INTEGER PRIMARY KEY,"\
39+
"name TEXT,"\
40+
"xml TEXT,"\
41+
"groupid INTEGER)"
42+
43+
_tag = "CREATE TABLE tag("\
44+
"id INTEGER PRIMARY KEY,"\
45+
"name TEXT)"
46+
47+
_tagmap = "CREATE TABLE tagmap("\
48+
"tag_id INTEGER NOT NULL,"\
49+
"symbol_id INTEGER)"
50+
51+
_symgroup = "CREATE TABLE symgroup("\
52+
"id INTEGER PRIMARY KEY,"\
53+
"name TEXT,"\
54+
"parent INTEGER)"
55+
56+
_smartgroup = "CREATE TABLE smartgroup("\
57+
"id INTEGER PRIMARY KEY,"\
58+
"name TEXT,"\
59+
"xml TEXT)"
60+
61+
_ctagmap = "CREATE TABLE ctagmap("\
62+
"tag_id INTEGER NOT NULL,"\
63+
"colorramp_id INTEGER)"
64+
65+
create_tables = [ _symbol, _colorramp, _tag, _tagmap, _ctagmap, _symgroup, _smartgroup ]
66+
67+
# Create the DB with required Schema
68+
conn = sqlite3.connect( dbfile )
69+
c = conn.cursor()
70+
print "Creating tables in the Database\n"
71+
for table in create_tables:
72+
try:
73+
c.execute( table )
74+
print table
75+
except sqlite3.OperationalError as e:
76+
pass
77+
conn.commit()
78+
79+
# parse the XML file & write symbol into DB
80+
dom = parse( xmlfile )
81+
symbols = dom.getElementsByTagName( "symbol" )
82+
for symbol in symbols:
83+
symbol_name = symbol.getAttribute( "name" )
84+
if '@' in symbol_name:
85+
parts = symbol_name.split('@')
86+
parent_name = parts[1]
87+
layerno = int(parts[2])
88+
c.execute( "SELECT xml FROM symbol WHERE name=(?)", (parent_name,) )
89+
symdom = parseString( c.fetchone()[0] ).getElementsByTagName( 'symbol' )[0]
90+
symdom.getElementsByTagName( "layer" )[ layerno ].appendChild( symbol )
91+
c.execute( "UPDATE symbol SET xml=? WHERE name=?", ( symdom.toxml(), parent_name ))
92+
else:
93+
c.execute( "INSERT INTO symbol VALUES (?,?,?,?)", ( None, symbol_name, symbol.toxml(), None ) )
94+
conn.commit()
95+
96+
97+
# ColorRamps
98+
colorramps = dom.getElementsByTagName( "colorramp" )
99+
for ramp in colorramps:
100+
ramp_name = ramp.getAttribute( "name" )
101+
c.execute( "INSERT INTO colorramp VALUES (?,?,?,?)", ( None, ramp_name, ramp.toxml(), None ) )
102+
conn.commit()
103+
104+
# Finally close the sqlite cursor
105+
c.close()

src/app/qgsdecorationgriddialog.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "qgsstylev2.h"
2525
#include "qgssymbolv2.h"
2626
#include "qgssymbolv2selectordialog.h"
27-
#include "qgssymbolv2propertiesdialog.h"
2827
#include "qgisapp.h"
2928

3029
#include <QFontDialog>
@@ -212,7 +211,7 @@ void QgsDecorationGridDialog::on_mLineSymbolButton_clicked()
212211
return;
213212

214213
QgsLineSymbolV2* lineSymbol = dynamic_cast<QgsLineSymbolV2*>( mLineSymbol->clone() );
215-
QgsSymbolV2PropertiesDialog dlg( lineSymbol, 0, this );
214+
QgsSymbolV2SelectorDialog dlg( lineSymbol, QgsStyleV2::defaultStyle(), 0, this );
216215
if ( dlg.exec() == QDialog::Rejected )
217216
{
218217
delete lineSymbol;
@@ -235,7 +234,7 @@ void QgsDecorationGridDialog::on_mMarkerSymbolButton_clicked()
235234
return;
236235

237236
QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mMarkerSymbol->clone() );
238-
QgsSymbolV2PropertiesDialog dlg( markerSymbol, 0, this );
237+
QgsSymbolV2SelectorDialog dlg( markerSymbol, QgsStyleV2::defaultStyle(), 0, this );
239238
if ( dlg.exec() == QDialog::Rejected )
240239
{
241240
delete markerSymbol;

src/core/qgsapplication.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,12 @@ const QString QgsApplication::svgPath()
557557

558558
const QString QgsApplication::userStyleV2Path()
559559
{
560-
return qgisSettingsDirPath() + QString( "symbology-ng-style.xml" );
560+
return qgisSettingsDirPath() + QString( "symbology-ng-style.db" );
561561
}
562562

563563
const QString QgsApplication::defaultStyleV2Path()
564564
{
565-
return ABISYM( mPkgDataPath ) + QString( "/resources/symbology-ng-style.xml" );
565+
return ABISYM( mPkgDataPath ) + QString( "/resources/symbology-ng-style.db" );
566566
}
567567

568568
const QString QgsApplication::libraryPath()

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,32 @@ QStringList QgsSvgMarkerSymbolLayerV2::listSvgFiles()
794794
return list;
795795
}
796796

797+
// Stripped down version of listSvgFiles() for specified directory
798+
QStringList QgsSvgMarkerSymbolLayerV2::listSvgFilesAt( QString directory )
799+
{
800+
// TODO anything that applies for the listSvgFiles() applies this also
801+
802+
QStringList list;
803+
QStringList svgPaths;
804+
svgPaths.append( directory );
805+
806+
for ( int i = 0; i < svgPaths.size(); i++ )
807+
{
808+
QDir dir( svgPaths[i] );
809+
foreach( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
810+
{
811+
svgPaths.insert( i + 1, dir.path() + "/" + item );
812+
}
813+
814+
foreach( QString item, dir.entryList( QStringList( "*.svg" ), QDir::Files ) )
815+
{
816+
list.append( dir.path() + "/" + item );
817+
}
818+
}
819+
return list;
820+
821+
}
822+
797823
QString QgsSvgMarkerSymbolLayerV2::symbolNameToPath( QString name )
798824
{
799825
// copied from QgsSymbol::setNamedPointSymbol - TODO: unify

src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
109109
//! Return a list of all available svg files
110110
static QStringList listSvgFiles();
111111

112+
//! Return a list of svg files at the specified directory
113+
static QStringList listSvgFilesAt( QString directory );
114+
112115
//! Get symbol's path from its name
113116
static QString symbolNameToPath( QString name );
114117

0 commit comments

Comments
 (0)