Skip to content
Permalink
Browse files

implemented SVG symbol grouping

Group tree implemented for SVG Marker symbols

implemented grouping for SVG Fill symbol widget
  • Loading branch information
tecoholic committed Jul 9, 2012
1 parent cbde7d4 commit b9b70f6fdd5bfc5fd56a9c37e7f27f55020a0c98
@@ -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
@@ -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 );

@@ -27,6 +27,8 @@

#include "qgsapplication.h"

#include "qgslogger.h"

#include <QAbstractButton>
#include <QColorDialog>
#include <QDir>
@@ -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() ) );
@@ -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 );
@@ -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 )
@@ -611,6 +671,7 @@ void QgsSvgMarkerSymbolLayerV2Widget::setGuiForSvg( const QgsSvgMarkerSymbolLaye
mBorderWidthSpinBox->blockSignals( true );
mBorderWidthSpinBox->setValue( layer->outlineWidth() );
mBorderWidthSpinBox->blockSignals( false );

}


@@ -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 )
@@ -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 );
@@ -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();
@@ -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();
@@ -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">
@@ -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">
@@ -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">
@@ -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>
@@ -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"/>

0 comments on commit b9b70f6

Please sign in to comment.
You can’t perform that action at this time.