13 changes: 13 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,20 @@ QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( QDomElement& element )
else
{
QgsSymbolLayerV2* layer = loadSymbolLayer( e );

if ( layer != NULL )
{
// Dealing with sub-symbols nested into a layer
QDomElement s = e.firstChildElement( "symbol" );
if ( !s.isNull() )
{
QgsSymbolV2* subSymbol = loadSymbol( s );
bool res = layer->setSubSymbol( subSymbol );
if ( !res )
QgsDebugMsg( "symbol layer refused subsymbol: " + s.attribute( "name" ) );
}
layers.append( layer );
}
}
}
layerNode = layerNode.nextSibling();
Expand Down Expand Up @@ -2175,6 +2187,7 @@ void QgsSymbolLayerV2Utils::saveProperties( QgsStringMap props, QDomDocument& do
}
}

// XXX Not used by QgStyleV2 anymore, But renderers use it still
QgsSymbolV2Map QgsSymbolLayerV2Utils::loadSymbols( QDomElement& element )
{
// go through symbols one-by-one and load them
Expand Down
83 changes: 83 additions & 0 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa

populateTypes();

QStandardItemModel* groupModel = new QStandardItemModel( groupTree );
groupTree->setModel( groupModel );
groupTree->setHeaderHidden( true );
populateGroups();
int rows = groupModel->rowCount( groupModel->indexFromItem( groupModel->invisibleRootItem() ) );
for ( int i = 0; i < rows; i++ )
{
groupTree->setExpanded( groupModel->indexFromItem( groupModel->item( i )), true );
}
connect( groupTree->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( groupChanged( const QModelIndex& ) ) );

connect( tabItemType, SIGNAL( currentChanged( int ) ), this, SLOT( populateList() ) );

populateList();
Expand Down Expand Up @@ -554,3 +565,75 @@ void QgsStyleV2ManagerDialog::importItems()
dlg.exec();
populateList();
}

void QgsStyleV2ManagerDialog::populateGroups()
{
QStandardItemModel *model = qobject_cast<QStandardItemModel*>( groupTree->model() );
model->clear();
// Add the groups
// 1. recently used
// 2. project
// 3. all symbol
// 4. group
//QStandardItem *allSymbols = new QStandardItem( "All Symbols" );

QStandardItem *group = new QStandardItem( "" ); //require empty name to get first order groups
buildGroupTree( group );
group->setText( "Groups" );//set title later
model->appendRow( group );

QStandardItem *tag = new QStandardItem( "Tags" );
buildTagTree( tag );
model->appendRow( tag );

}

void QgsStyleV2ManagerDialog::buildGroupTree( QStandardItem* &parent )
{
QgsSymbolGroupMap groups = mStyle->groupNames( parent->text() );
QgsSymbolGroupMap::const_iterator i = groups.constBegin();
while ( i != groups.constEnd() )
{
QStandardItem *item = new QStandardItem( i.value() );
item->setData( QVariant( i.key() ) );
parent->appendRow( item );
QgsDebugMsg( "Added Group: " + i.value() );
buildGroupTree( item );
++i;
}

}
void QgsStyleV2ManagerDialog::buildTagTree( QStandardItem* &parent )
{
Q_UNUSED( parent );
// FIXME

}

void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
{
int groupId = index.data( Qt::UserRole + 1 ).toInt();

int type = currentItemType();
QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
model->clear();

QStringList symbolNames = mStyle->symbolsOfGroup( groupId );

for ( int i = 0; i < symbolNames.count(); ++i )
{
QString name = symbolNames[i];
QgsSymbolV2* symbol = mStyle->symbol( name );
if ( symbol->type() == 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 );
}
delete symbol;
}
}

9 changes: 9 additions & 0 deletions src/gui/symbology-ng/qgsstylev2managerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,20 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV

void itemChanged( QStandardItem* item );

void groupChanged( const QModelIndex& );

protected:

//! populate combo box with known style items (symbols, color ramps)
void populateTypes();

//! populate the groups
void populateGroups();
//! build the groups tree
void buildGroupTree( QStandardItem* &parent );
//! build the tag tree
void buildTagTree( QStandardItem* &parent );

//! populate list view with symbols of specified type
void populateSymbols( int type );
//! populate list view with color ramps
Expand Down
311 changes: 169 additions & 142 deletions src/ui/qgsstylev2managerdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,179 +13,206 @@
<property name="windowTitle">
<string>Style Manager</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabItemType">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTreeView" name="groupTree">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="iconSize">
<property name="maximumSize">
<size>
<width>22</width>
<height>22</height>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<widget class="QWidget" name="tabMarker">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/styleicons/style-point.png</normaloff>:/images/themes/default/styleicons/style-point.png</iconset>
</attribute>
<attribute name="title">
<string>Marker</string>
</attribute>
</widget>
<widget class="QWidget" name="tabLine">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/styleicons/style-line.png</normaloff>:/images/themes/default/styleicons/style-line.png</iconset>
</attribute>
<attribute name="title">
<string>Line</string>
</attribute>
</widget>
<widget class="QWidget" name="tabFill">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/styleicons/style-polygon.png</normaloff>:/images/themes/default/styleicons/style-polygon.png</iconset>
</attribute>
<attribute name="title">
<string>Fill</string>
</attribute>
</widget>
<widget class="QWidget" name="tabColorRamp">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/styleicons/color.png</normaloff>:/images/themes/default/styleicons/color.png</iconset>
</attribute>
<attribute name="title">
<string>Color ramp</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QListView" name="listItems">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>3</verstretch>
</sizepolicy>
</property>
<property name="editTriggers">
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>5</number>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QPushButton" name="btnAddItem">
<property name="toolTip">
<string>Add item</string>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="text">
<string>Add</string>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnEditItem">
<property name="toolTip">
<string>Edit item</string>
<item row="2" column="0" colspan="2">
<widget class="QListView" name="listItems">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>3</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Edit</string>
<property name="editTriggers">
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRemoveItem">
<property name="toolTip">
<string>Remove item</string>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="text">
<string>Remove</string>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="spacing">
<number>5</number>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="1" column="0" colspan="2">
<widget class="QTabWidget" name="tabItemType">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<property name="currentIndex">
<number>0</number>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>20</height>
<width>22</width>
<height>22</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnExportItems">
<property name="text">
<string>Export...</string>
</property>
<widget class="QWidget" name="tabMarker">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/styleicons/style-point.png</normaloff>:/images/themes/default/styleicons/style-point.png</iconset>
</attribute>
<attribute name="title">
<string>Marker</string>
</attribute>
</widget>
<widget class="QWidget" name="tabLine">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/styleicons/style-line.png</normaloff>:/images/themes/default/styleicons/style-line.png</iconset>
</attribute>
<attribute name="title">
<string>Line</string>
</attribute>
</widget>
<widget class="QWidget" name="tabFill">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/styleicons/style-polygon.png</normaloff>:/images/themes/default/styleicons/style-polygon.png</iconset>
</attribute>
<attribute name="title">
<string>Fill</string>
</attribute>
</widget>
<widget class="QWidget" name="tabColorRamp">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/styleicons/color.png</normaloff>:/images/themes/default/styleicons/color.png</iconset>
</attribute>
<attribute name="title">
<string>Color ramp</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnImportItems">
<item row="0" column="1">
<widget class="QLineEdit" name="searchBox">
<property name="text">
<string>Import...</string>
<string/>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout">
<item>
<widget class="QPushButton" name="btnAddItem">
<property name="toolTip">
<string>Add item</string>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnEditItem">
<property name="toolTip">
<string>Edit item</string>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRemoveItem">
<property name="toolTip">
<string>Remove item</string>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnExportItems">
<property name="text">
<string>Export...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnImportItems">
<property name="text">
<string>Import...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<item row="1" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down