Skip to content

Commit b9b70f6

Browse files
author
Arunmozhi
committedJul 9, 2012
implemented SVG symbol grouping
Group tree implemented for SVG Marker symbols implemented grouping for SVG Fill symbol widget
1 parent cbde7d4 commit b9b70f6

File tree

6 files changed

+148
-21
lines changed

6 files changed

+148
-21
lines changed
 

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,20 @@ 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+
QStringList list;
802+
803+
QDir dir( directory );
804+
foreach( QString item, dir.entryList( QStringList( "*.svg" ), QDir::Files ) )
805+
{
806+
list.append( dir.path() + "/" + item );
807+
}
808+
return list;
809+
}
810+
797811
QString QgsSvgMarkerSymbolLayerV2::symbolNameToPath( QString name )
798812
{
799813
// 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

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include "qgsapplication.h"
2929

30+
#include "qgslogger.h"
31+
3032
#include <QAbstractButton>
3133
#include <QColorDialog>
3234
#include <QDir>
@@ -519,10 +521,12 @@ QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget( const QgsVecto
519521
mLayer = NULL;
520522

521523
setupUi( this );
524+
viewGroups->setHeaderHidden( true );
522525

523526
populateList();
524527

525528
connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
529+
connect( viewGroups->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
526530
connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
527531
connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
528532
connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
@@ -541,6 +545,12 @@ class QgsSvgListModel : public QAbstractListModel
541545
mSvgFiles = QgsSvgMarkerSymbolLayerV2::listSvgFiles();
542546
}
543547

548+
// Constructor to create model for icons in a specific path
549+
QgsSvgListModel( QObject* parent, QString path ) : QAbstractListModel( parent )
550+
{
551+
mSvgFiles = QgsSvgMarkerSymbolLayerV2::listSvgFilesAt( path );
552+
}
553+
544554
int rowCount( const QModelIndex & parent = QModelIndex() ) const
545555
{
546556
Q_UNUSED( parent );
@@ -581,11 +591,61 @@ class QgsSvgListModel : public QAbstractListModel
581591
QStringList mSvgFiles;
582592
};
583593

594+
class QgsSvgGroupsModel : public QStandardItemModel
595+
{
596+
public:
597+
QgsSvgGroupsModel( QObject* parent ) : QStandardItemModel( parent )
598+
{
599+
QStringList svgPaths = QgsApplication::svgPaths();
600+
QStandardItem *parentItem = invisibleRootItem();
601+
602+
for ( int i = 0; i < svgPaths.size(); i++ )
603+
{
604+
QDir dir( svgPaths[i] );
605+
QStandardItem *baseGroup = new QStandardItem( dir.dirName() );
606+
baseGroup->setData( QVariant( svgPaths[i] ) );
607+
baseGroup->setEditable( false );
608+
baseGroup->setCheckable( false );
609+
parentItem->appendRow( baseGroup );
610+
createTree( baseGroup );
611+
QgsDebugMsg( QString( "SVG base path %1: %2" ).arg( i ).arg( baseGroup->data().toString() ) );
612+
}
613+
}
614+
private:
615+
void createTree( QStandardItem* &parentGroup )
616+
{
617+
QDir parentDir( parentGroup->data().toString() );
618+
foreach( QString item, parentDir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
619+
{
620+
QStandardItem* group = new QStandardItem( item );
621+
group->setData( QVariant( parentDir.path() + "/" + item ) );
622+
group->setEditable( false );
623+
group->setCheckable( false );
624+
parentGroup->appendRow( group );
625+
createTree( group );
626+
}
627+
}
628+
};
629+
584630
void QgsSvgMarkerSymbolLayerV2Widget::populateList()
585631
{
632+
QgsSvgGroupsModel* g = new QgsSvgGroupsModel( viewGroups );
633+
viewGroups->setModel( g );
634+
635+
// Initally load the icons in the List view without any grouping
586636
QgsSvgListModel* m = new QgsSvgListModel( viewImages );
637+
viewImages->setModel( m );
638+
}
587639

640+
void QgsSvgMarkerSymbolLayerV2Widget::populateIcons( const QModelIndex& idx )
641+
{
642+
QString path = idx.data( Qt::UserRole + 1 ).toString();
643+
644+
QgsSvgListModel* m = new QgsSvgListModel( viewImages, path );
588645
viewImages->setModel( m );
646+
647+
connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
648+
emit changed();
589649
}
590650

591651
void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QgsSvgMarkerSymbolLayerV2* layer )
@@ -611,6 +671,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QgsSvgMarkerSymbolLaye
611671
mBorderWidthSpinBox->blockSignals( true );
612672
mBorderWidthSpinBox->setValue( layer->outlineWidth() );
613673
mBorderWidthSpinBox->blockSignals( false );
674+
614675
}
615676

616677

@@ -816,10 +877,12 @@ QgsSVGFillSymbolLayerWidget::QgsSVGFillSymbolLayerWidget( const QgsVectorLayer*
816877
{
817878
mLayer = 0;
818879
setupUi( this );
880+
mSvgTreeView->setHeaderHidden( true );
819881
insertIcons();
820882
updateOutlineIcon();
821883

822884
connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
885+
connect( mSvgTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
823886
}
824887

825888
void QgsSVGFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer )
@@ -895,10 +958,24 @@ void QgsSVGFillSymbolLayerWidget::setFile( const QModelIndex& item )
895958

896959
void QgsSVGFillSymbolLayerWidget::insertIcons()
897960
{
961+
QgsSvgGroupsModel* g = new QgsSvgGroupsModel( mSvgTreeView );
962+
mSvgTreeView->setModel( g );
963+
898964
QgsSvgListModel* m = new QgsSvgListModel( mSvgListView );
899965
mSvgListView->setModel( m );
900966
}
901967

968+
void QgsSVGFillSymbolLayerWidget::populateIcons( const QModelIndex& idx )
969+
{
970+
QString path = idx.data( Qt::UserRole + 1 ).toString();
971+
972+
QgsSvgListModel* m = new QgsSvgListModel( mSvgListView, path );
973+
mSvgListView->setModel( m );
974+
975+
connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
976+
emit changed();
977+
}
978+
902979
void QgsSVGFillSymbolLayerWidget::on_mChangeOutlinePushButton_clicked()
903980
{
904981
QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), mVectorLayer, this );

‎src/gui/symbology-ng/qgssymbollayerv2widget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget
195195

196196
public slots:
197197
void setName( const QModelIndex& idx );
198+
void populateIcons( const QModelIndex& idx );
198199
void setSize();
199200
void setAngle();
200201
void setOffset();
@@ -273,6 +274,7 @@ class GUI_EXPORT QgsSVGFillSymbolLayerWidget : public QgsSymbolLayerV2Widget, pr
273274
void on_mTextureWidthSpinBox_valueChanged( double d );
274275
void on_mSVGLineEdit_textChanged( const QString & text );
275276
void setFile( const QModelIndex& item );
277+
void populateIcons( const QModelIndex& item );
276278
void on_mChangeOutlinePushButton_clicked();
277279
void on_mRotationSpinBox_valueChanged( double d );
278280
void on_mChangeColorButton_clicked();

‎src/ui/symbollayer/widget_svgfill.ui

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>236</width>
10-
<height>310</height>
9+
<width>239</width>
10+
<height>346</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout_2">
16+
<layout class="QGridLayout" name="gridLayout_3">
1717
<item row="0" column="0">
1818
<layout class="QGridLayout" name="gridLayout">
1919
<item row="0" column="0">
@@ -106,20 +106,41 @@
106106
</layout>
107107
</item>
108108
<item row="1" column="0">
109-
<widget class="QListView" name="mSvgListView">
110-
<property name="flow">
111-
<enum>QListView::LeftToRight</enum>
112-
</property>
113-
<property name="layoutMode">
114-
<enum>QListView::Batched</enum>
115-
</property>
116-
<property name="viewMode">
117-
<enum>QListView::IconMode</enum>
118-
</property>
119-
<property name="uniformItemSizes">
120-
<bool>true</bool>
121-
</property>
122-
</widget>
109+
<layout class="QGridLayout" name="gridLayout_2">
110+
<item row="0" column="0">
111+
<widget class="QLabel" name="mSymbolGroupLabel">
112+
<property name="text">
113+
<string>SVG Groups</string>
114+
</property>
115+
</widget>
116+
</item>
117+
<item row="0" column="1">
118+
<widget class="QLabel" name="mSymbolListLabel">
119+
<property name="text">
120+
<string>SVG Symbols</string>
121+
</property>
122+
</widget>
123+
</item>
124+
<item row="1" column="0">
125+
<widget class="QTreeView" name="mSvgTreeView"/>
126+
</item>
127+
<item row="1" column="1">
128+
<widget class="QListView" name="mSvgListView">
129+
<property name="flow">
130+
<enum>QListView::LeftToRight</enum>
131+
</property>
132+
<property name="layoutMode">
133+
<enum>QListView::Batched</enum>
134+
</property>
135+
<property name="viewMode">
136+
<enum>QListView::IconMode</enum>
137+
</property>
138+
<property name="uniformItemSizes">
139+
<bool>true</bool>
140+
</property>
141+
</widget>
142+
</item>
143+
</layout>
123144
</item>
124145
<item row="2" column="0">
125146
<layout class="QHBoxLayout" name="horizontalLayout">

‎src/ui/symbollayer/widget_svgmarker.ui

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>302</width>
10-
<height>337</height>
9+
<width>364</width>
10+
<height>361</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
17-
<item row="0" column="0">
17+
<item row="0" column="0" colspan="2">
1818
<layout class="QGridLayout">
1919
<item row="0" column="0">
2020
<widget class="QLabel" name="label_2">
@@ -163,13 +163,23 @@
163163
</layout>
164164
</item>
165165
<item row="1" column="0">
166+
<widget class="QLabel" name="label_5">
167+
<property name="text">
168+
<string>SVG Groups</string>
169+
</property>
170+
</widget>
171+
</item>
172+
<item row="1" column="1">
166173
<widget class="QLabel" name="label">
167174
<property name="text">
168175
<string>SVG Image</string>
169176
</property>
170177
</widget>
171178
</item>
172179
<item row="2" column="0">
180+
<widget class="QTreeView" name="viewGroups"/>
181+
</item>
182+
<item row="2" column="1">
173183
<widget class="QListView" name="viewImages">
174184
<property name="editTriggers">
175185
<set>QAbstractItemView::NoEditTriggers</set>
@@ -209,7 +219,7 @@
209219
</property>
210220
</widget>
211221
</item>
212-
<item row="3" column="0">
222+
<item row="3" column="0" colspan="2">
213223
<layout class="QHBoxLayout" name="horizontalLayout_2">
214224
<item>
215225
<widget class="QLineEdit" name="mFileLineEdit"/>

0 commit comments

Comments
 (0)
Please sign in to comment.