Skip to content

Commit

Permalink
Merge pull request #3755 from nirvn/style_manager_upgrade
Browse files Browse the repository at this point in the history
[FEATURE] Style management re-work and upgrade
  • Loading branch information
nyalldawson authored Nov 17, 2016
2 parents 964ecfd + 5e487cf commit e624518
Show file tree
Hide file tree
Showing 30 changed files with 1,186 additions and 929 deletions.
5 changes: 5 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,11 @@ QgsSvgCache {#qgis_api_break_3_0_QgsSvgCache}

- containsParamsV2() was removed. Use containsParamsV3() instead.

QgsStyle (renamed from QgsStyleV2) {#qgis_api_break_3_0_QgsStyle}
----------------------------------
- All group functions have been removed: group(), addGroup(), groupId(), groupName(), groupNames(), groupIds(), symbolsOfGroup(), getGroupRemoveQuery()
- The StyleEntity::GroupEntity has been removed
- The SymgroupTable enum has been removed

QgsSymbol (renamed from QgsSymbolV2) {#qgis_api_break_3_0_QgsSymbol}
------------------------------------
Expand Down
200 changes: 98 additions & 102 deletions python/core/symbology-ng/qgsstyle.sip

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions python/gui/gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
%Include symbology-ng/qgsstyleexportimportdialog.sip
%Include symbology-ng/qgsstylegroupselectiondialog.sip
%Include symbology-ng/qgsstylemanagerdialog.sip
%Include symbology-ng/qgsstylesavedialog.sip
%Include symbology-ng/qgssvgselectorwidget.sip
%Include symbology-ng/qgssymbollayerwidget.sip
%Include symbology-ng/qgssymbollevelsdialog.sip
Expand Down
12 changes: 6 additions & 6 deletions python/gui/symbology-ng/qgsstyleexportimportdialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class QgsStyleExportImportDialog : QDialog
*/
void clearSelection();
/**
* Select the symbols belonging to the given group
* @param groupName the name of the group to be selected
* Select the symbols belonging to the given tag
* @param tagName the name of the tag to be selected
*/
void selectGroup( const QString& groupName );
void selectTag( const QString& tagName );
/**
* Deselect the symbols belonging to the given group
* @param groupName the name of the group to be deselected
* Deselect the symbols belonging to the given tag
* @param tagName the name of the tag to be deselected
*/
void deselectGroup( const QString& groupName );
void deselectTag( const QString& tagName );
/**
* @brief selectSmartgroup selects all symbols from a smart group
* @param groupName
Expand Down
8 changes: 4 additions & 4 deletions python/gui/symbology-ng/qgsstylegroupselectiondialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class QgsStyleGroupSelectionDialog : public QDialog, private Ui::SymbolsGroupSel
void setBold( QStandardItem *item );

signals:
//! group with groupName has been selected
void groupSelected( const QString& groupName );
//! group with groupName has been deselected
void groupDeselected( const QString& groupName );
//! tag with tagName has been selected
void tagSelected( const QString& tagName );
//! tag with tagName has been deselected
void tagDeselected( const QString& tagName );
//! smartgroup with groupName has been selected
void smartgroupSelected( const QString& groupName );
//! smart group with groupName has been deselected
Expand Down
21 changes: 10 additions & 11 deletions python/gui/symbology-ng/qgsstylemanagerdialog.sip
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class QgsStyleManagerDialog : QDialog
void addGroup();
void removeGroup();

//! carryout symbol grouping using check boxes
void groupSymbolsAction();
//! carry out symbol tagging using check boxes
void tagSymbolsAction();

//! edit the selected smart group
void editSmartgroupAction();
Expand All @@ -49,9 +49,6 @@ class QgsStyleManagerDialog : QDialog
//! filter the symbols based on input search term
void filterSymbols( const QString& );

//! Listen to tag changes
void tagsChanged();

//! Perform symbol specific tasks when selected
void symbolSelected( const QModelIndex& );

Expand All @@ -66,7 +63,14 @@ class QgsStyleManagerDialog : QDialog

protected slots:
bool addColorRamp( QAction* action );
void groupSelectedSymbols();
//! Add selected symbols to favorites
void addFavoriteSelectedSymbols();
//! Remove selected symbols from favorites
void removeFavoriteSelectedSymbols();
//! Tag selected symbols using menu item selection
void tagSelectedSymbols();
//! Remove all tags from selected symbols
void detagSelectedSymbols();

protected:

Expand All @@ -75,8 +79,6 @@ class QgsStyleManagerDialog : QDialog

//! populate the groups
void populateGroups();
//! build the groups tree
void buildGroupTree( QStandardItem* &parent );
//! to set symbols checked when in editing mode
void setSymbolsChecked( const QStringList& );

Expand Down Expand Up @@ -107,9 +109,6 @@ class QgsStyleManagerDialog : QDialog
//! Enables or diables the groupTree items for grouping mode
void enableItemsForGroupingMode( bool );

//! Event filter to capture tagsLineEdit out of focus
bool eventFilter( QObject*, QEvent* );

//! sets the text of the item with bold font
void setBold( QStandardItem* );
};
22 changes: 22 additions & 0 deletions python/gui/symbology-ng/qgsstylesavedialog.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class QgsStyleSaveDialog : QDialog
{
%TypeHeaderCode
#include <qgsstylesavedialog.h>
%End

public:
/** Constructor for QgsSymbolSaveDialog
* @param parent parent widget
* @param type the QgsStyle entity type being saved
*/
QgsStyleSaveDialog( QWidget* parent /TransferThis/ = NULL, QgsStyle::StyleEntity type = QgsStyle::SymbolEntity );

//! returns the text value of the name element
QString name() const;

//! returns the text value of the tags element
QString tags() const;

//! returns whether the favorite element is checked
bool isFavorite() const;
};
3 changes: 2 additions & 1 deletion python/gui/symbology-ng/qgssymbolslistwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class QgsSymbolsListWidget : QWidget
void on_mSymbolUnitWidget_changed();
void on_mTransparencySlider_valueChanged( int value );

//! Pupulates the groups combo box with available tags and smartgroups
void populateGroups();
void on_groupsCombo_currentIndexChanged( int index );
void on_groupsCombo_editTextChanged( const QString &text );

void openStyleManager();
void clipFeaturesToggled( bool checked );
Expand Down
Binary file modified resources/symbology-ng-style.db
Binary file not shown.
2 changes: 1 addition & 1 deletion resources/symbology-ng-style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@
<prop k="width_unit" v="MM"/>
</layer>
</symbol>
<symbol alpha="1" type="marker" name="airport">
<symbol alpha="1" type="marker" name="airport" favorite="1">
<layer pass="0" class="SvgMarker" locked="0">
<prop k="angle" v="0"/>
<prop k="fill" v="#000000"/>
Expand Down
51 changes: 27 additions & 24 deletions scripts/symbol_xml2db.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
"id INTEGER PRIMARY KEY,"\
"name TEXT UNIQUE,"\
"xml TEXT,"\
"groupid INTEGER)"
"favorite INTEGER)"

_colorramp = "CREATE TABLE colorramp("\
"id INTEGER PRIMARY KEY,"\
"name TEXT UNIQUE,"\
"xml TEXT,"\
"groupid INTEGER)"
"favorite INTEGER)"

_tag = "CREATE TABLE tag("\
"id INTEGER PRIMARY KEY,"\
Expand All @@ -48,57 +48,60 @@
"tag_id INTEGER NOT NULL,"\
"symbol_id INTEGER)"

_symgroup = "CREATE TABLE symgroup("\
"id INTEGER PRIMARY KEY,"\
"name TEXT,"\
"parent INTEGER)"
_ctagmap = "CREATE TABLE ctagmap("\
"tag_id INTEGER NOT NULL,"\
"colorramp_id INTEGER)"

_smartgroup = "CREATE TABLE smartgroup("\
"id INTEGER PRIMARY KEY,"\
"name TEXT,"\
"xml TEXT)"

_ctagmap = "CREATE TABLE ctagmap("\
"tag_id INTEGER NOT NULL,"\
"colorramp_id INTEGER)"

create_tables = [ _symbol, _colorramp, _tag, _tagmap, _ctagmap, _symgroup, _smartgroup ]
create_tables = [_symbol, _colorramp, _tag, _tagmap, _ctagmap, _smartgroup]

# Create the DB with required Schema
conn = sqlite3.connect( dbfile )
conn = sqlite3.connect(dbfile)
c = conn.cursor()
print "Creating tables in the Database\n"
for table in create_tables:
try:
c.execute( table )
c.execute(table)
print table
except sqlite3.OperationalError as e:
pass
conn.commit()

# parse the XML file & write symbol into DB
dom = parse( xmlfile )
symbols = dom.getElementsByTagName( "symbol" )
dom = parse(xmlfile)
symbols = dom.getElementsByTagName("symbol")
for symbol in symbols:
symbol_name = symbol.getAttribute( "name" )
symbol_name = symbol.getAttribute("name")
symbol_favorite = symbol.getAttribute("favorite")
if not symbol_favorite:
symbol_favorite = 0

if '@' in symbol_name:
parts = symbol_name.split('@')
parent_name = parts[1]
layerno = int(parts[2])
c.execute( "SELECT xml FROM symbol WHERE name=(?)", (parent_name,) )
symdom = parseString( c.fetchone()[0] ).getElementsByTagName( 'symbol' )[0]
symdom.getElementsByTagName( "layer" )[ layerno ].appendChild( symbol )
c.execute( "UPDATE symbol SET xml=? WHERE name=?", ( symdom.toxml(), parent_name ))
c.execute("SELECT xml FROM symbol WHERE name=(?)", (parent_name,))
symdom = parseString(c.fetchone()[0]).getElementsByTagName('symbol')[0]
symdom.getElementsByTagName("layer")[layerno].appendChild(symbol)
c.execute("UPDATE symbol SET xml=? WHERE name=?", (symdom.toxml(), parent_name))
else:
c.execute( "INSERT INTO symbol VALUES (?,?,?,?)", ( None, symbol_name, symbol.toxml(), 0 ) )
c.execute("INSERT INTO symbol VALUES (?,?,?,?)", (None, symbol_name, symbol.toxml(), symbol_favorite))
conn.commit()


# ColorRamps
colorramps = dom.getElementsByTagName( "colorramp" )
colorramps = dom.getElementsByTagName("colorramp")
for ramp in colorramps:
ramp_name = ramp.getAttribute( "name" )
c.execute( "INSERT INTO colorramp VALUES (?,?,?,?)", ( None, ramp_name, ramp.toxml(), 0 ) )
ramp_name = ramp.getAttribute("name")
symbol_favorite = symbol.getAttribute("favorite")
if not symbol_favorite:
symbol_favorite = 0

c.execute("INSERT INTO colorramp VALUES (?,?,?,?)", (None, ramp_name, ramp.toxml(), symbol_favorite))
conn.commit()

# Finally close the sqlite cursor
Expand Down
Loading

0 comments on commit e624518

Please sign in to comment.