Skip to content

Commit

Permalink
implemented SVG symbol grouping
Browse files Browse the repository at this point in the history
Group tree implemented for SVG Marker symbols

implemented grouping for SVG Fill symbol widget
  • Loading branch information
Arunmozhi committed Jul 9, 2012
1 parent cbde7d4 commit b9b70f6
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 21 deletions.
14 changes: 14 additions & 0 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -794,6 +794,20 @@ QStringList QgsSvgMarkerSymbolLayerV2::listSvgFiles()
return list;
}

// Stripped down version of listSvgFiles() for specified directory
QStringList QgsSvgMarkerSymbolLayerV2::listSvgFilesAt( QString directory )
{
// TODO anything that applies for the listSvgFiles() applies this also
QStringList list;

QDir dir( directory );
foreach( QString item, dir.entryList( QStringList( "*.svg" ), QDir::Files ) )
{
list.append( dir.path() + "/" + item );
}
return list;
}

QString QgsSvgMarkerSymbolLayerV2::symbolNameToPath( QString name )
{
// copied from QgsSymbol::setNamedPointSymbol - TODO: unify
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Expand Up @@ -109,6 +109,9 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
//! Return a list of all available svg files
static QStringList listSvgFiles();

//! Return a list of svg files at the specified directory
static QStringList listSvgFilesAt( QString directory );

//! Get symbol's path from its name
static QString symbolNameToPath( QString name );

Expand Down
77 changes: 77 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -27,6 +27,8 @@

#include "qgsapplication.h"

#include "qgslogger.h"

#include <QAbstractButton>
#include <QColorDialog>
#include <QDir>
Expand Down Expand Up @@ -519,10 +521,12 @@ QgsSvgMarkerSymbolLayerV2Widget::QgsSvgMarkerSymbolLayerV2Widget( const QgsVecto
mLayer = NULL;

setupUi( this );
viewGroups->setHeaderHidden( true );

populateList();

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

// Constructor to create model for icons in a specific path
QgsSvgListModel( QObject* parent, QString path ) : QAbstractListModel( parent )
{
mSvgFiles = QgsSvgMarkerSymbolLayerV2::listSvgFilesAt( path );
}

int rowCount( const QModelIndex & parent = QModelIndex() ) const
{
Q_UNUSED( parent );
Expand Down Expand Up @@ -581,11 +591,61 @@ class QgsSvgListModel : public QAbstractListModel
QStringList mSvgFiles;
};

class QgsSvgGroupsModel : public QStandardItemModel
{
public:
QgsSvgGroupsModel( QObject* parent ) : QStandardItemModel( parent )
{
QStringList svgPaths = QgsApplication::svgPaths();
QStandardItem *parentItem = invisibleRootItem();

for ( int i = 0; i < svgPaths.size(); i++ )
{
QDir dir( svgPaths[i] );
QStandardItem *baseGroup = new QStandardItem( dir.dirName() );
baseGroup->setData( QVariant( svgPaths[i] ) );
baseGroup->setEditable( false );
baseGroup->setCheckable( false );
parentItem->appendRow( baseGroup );
createTree( baseGroup );
QgsDebugMsg( QString( "SVG base path %1: %2" ).arg( i ).arg( baseGroup->data().toString() ) );
}
}
private:
void createTree( QStandardItem* &parentGroup )
{
QDir parentDir( parentGroup->data().toString() );
foreach( QString item, parentDir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
{
QStandardItem* group = new QStandardItem( item );
group->setData( QVariant( parentDir.path() + "/" + item ) );
group->setEditable( false );
group->setCheckable( false );
parentGroup->appendRow( group );
createTree( group );
}
}
};

void QgsSvgMarkerSymbolLayerV2Widget::populateList()
{
QgsSvgGroupsModel* g = new QgsSvgGroupsModel( viewGroups );
viewGroups->setModel( g );

// Initally load the icons in the List view without any grouping
QgsSvgListModel* m = new QgsSvgListModel( viewImages );
viewImages->setModel( m );
}

void QgsSvgMarkerSymbolLayerV2Widget::populateIcons( const QModelIndex& idx )
{
QString path = idx.data( Qt::UserRole + 1 ).toString();

QgsSvgListModel* m = new QgsSvgListModel( viewImages, path );
viewImages->setModel( m );

connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
emit changed();
}

void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QgsSvgMarkerSymbolLayerV2* layer )
Expand All @@ -611,6 +671,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QgsSvgMarkerSymbolLaye
mBorderWidthSpinBox->blockSignals( true );
mBorderWidthSpinBox->setValue( layer->outlineWidth() );
mBorderWidthSpinBox->blockSignals( false );

}


Expand Down Expand Up @@ -816,10 +877,12 @@ QgsSVGFillSymbolLayerWidget::QgsSVGFillSymbolLayerWidget( const QgsVectorLayer*
{
mLayer = 0;
setupUi( this );
mSvgTreeView->setHeaderHidden( true );
insertIcons();
updateOutlineIcon();

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

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

void QgsSVGFillSymbolLayerWidget::insertIcons()
{
QgsSvgGroupsModel* g = new QgsSvgGroupsModel( mSvgTreeView );
mSvgTreeView->setModel( g );

QgsSvgListModel* m = new QgsSvgListModel( mSvgListView );
mSvgListView->setModel( m );
}

void QgsSVGFillSymbolLayerWidget::populateIcons( const QModelIndex& idx )
{
QString path = idx.data( Qt::UserRole + 1 ).toString();

QgsSvgListModel* m = new QgsSvgListModel( mSvgListView, path );
mSvgListView->setModel( m );

connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
emit changed();
}

void QgsSVGFillSymbolLayerWidget::on_mChangeOutlinePushButton_clicked()
{
QgsSymbolV2PropertiesDialog dlg( mLayer->subSymbol(), mVectorLayer, this );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -195,6 +195,7 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget

public slots:
void setName( const QModelIndex& idx );
void populateIcons( const QModelIndex& idx );
void setSize();
void setAngle();
void setOffset();
Expand Down Expand Up @@ -273,6 +274,7 @@ class GUI_EXPORT QgsSVGFillSymbolLayerWidget : public QgsSymbolLayerV2Widget, pr
void on_mTextureWidthSpinBox_valueChanged( double d );
void on_mSVGLineEdit_textChanged( const QString & text );
void setFile( const QModelIndex& item );
void populateIcons( const QModelIndex& item );
void on_mChangeOutlinePushButton_clicked();
void on_mRotationSpinBox_valueChanged( double d );
void on_mChangeColorButton_clicked();
Expand Down
55 changes: 38 additions & 17 deletions src/ui/symbollayer/widget_svgfill.ui
Expand Up @@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>236</width>
<height>310</height>
<width>239</width>
<height>346</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
Expand Down Expand Up @@ -106,20 +106,41 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QListView" name="mSvgListView">
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="layoutMode">
<enum>QListView::Batched</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="mSymbolGroupLabel">
<property name="text">
<string>SVG Groups</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="mSymbolListLabel">
<property name="text">
<string>SVG Symbols</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTreeView" name="mSvgTreeView"/>
</item>
<item row="1" column="1">
<widget class="QListView" name="mSvgListView">
<property name="flow">
<enum>QListView::LeftToRight</enum>
</property>
<property name="layoutMode">
<enum>QListView::Batched</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
Expand Down
18 changes: 14 additions & 4 deletions src/ui/symbollayer/widget_svgmarker.ui
Expand Up @@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>302</width>
<height>337</height>
<width>364</width>
<height>361</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
Expand Down Expand Up @@ -163,13 +163,23 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>SVG Groups</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>SVG Image</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QTreeView" name="viewGroups"/>
</item>
<item row="2" column="1">
<widget class="QListView" name="viewImages">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
Expand Down Expand Up @@ -209,7 +219,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="mFileLineEdit"/>
Expand Down

0 comments on commit b9b70f6

Please sign in to comment.