QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgssvgselectorwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssvgselectorwidget.h - group and preview selector for SVG files
3  built off of work in qgssymbollayerv2widget
4 
5  ---------------------
6  begin : April 2, 2013
7  copyright : (C) 2013 by Larry Shaffer
8  email : larrys at dakcarto dot com
9  ***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSSVGSELECTORWIDGET_H
18 #define QGSSVGSELECTORWIDGET_H
19 
20 #include "ui_widget_svgselector.h"
21 
22 #include "qgisgui.h"
23 
24 #include <QAbstractListModel>
25 #include <QDialog>
26 #include <QDialogButtonBox>
27 #include <QLayout>
28 #include <QStandardItemModel>
29 #include <QWidget>
30 
31 class QCheckBox;
32 class QLayout;
33 class QLineEdit;
34 class QListView;
35 class QPushButton;
36 class QTreeView;
37 
38 class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
39 {
40  public:
41  QgsSvgSelectorListModel( QObject* parent );
42 
43  // Constructor to create model for icons in a specific path
44  QgsSvgSelectorListModel( QObject* parent, QString path );
45 
46  int rowCount( const QModelIndex & parent = QModelIndex() ) const;
47 
48  QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const;
49 
50  protected:
51  QStringList mSvgFiles;
52 };
53 
54 class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
55 {
56  public:
57  QgsSvgSelectorGroupsModel( QObject* parent );
58 
59  private:
60  void createTree( QStandardItem* &parentGroup );
61 };
62 
63 
64 class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
65 {
66  Q_OBJECT
67 
68  public:
69  QgsSvgSelectorWidget( QWidget* parent = 0 );
71 
72  static QgsSvgSelectorWidget* create( QWidget* parent = 0 ) { return new QgsSvgSelectorWidget( parent ); }
73 
74  QString currentSvgPath() const;
75  QString currentSvgPathToName() const;
76 
77  QTreeView* groupsTreeView() { return mGroupsTreeView; }
78  QListView* imagesListView() { return mImagesListView; }
79  QLineEdit* filePathLineEdit() { return mFileLineEdit; }
80  QPushButton* filePathButton() { return mFilePushButton; }
81  QCheckBox* relativePathCheckbox() { return mRelativePathChkBx; }
82  QLayout* selectorLayout() { return this->layout(); }
83 
84  public slots:
86  void setSvgPath( const QString& svgPath );
87 
88  signals:
89  void svgSelected( const QString& path );
90 
91  protected:
92  void populateList();
93 
94  private slots:
95  void populateIcons( const QModelIndex& idx );
96  void svgSelectionChanged( const QModelIndex& idx );
97  void updateCurrentSvgPath( const QString& svgPath );
98 
99  void on_mFilePushButton_clicked();
100  void updateLineEditFeedback( bool ok, QString tip = QString( "" ) );
101  void on_mFileLineEdit_textChanged( const QString& text );
102 
103  private:
104  QString mCurrentSvgPath; // always stored as absolute path
105 };
106 
107 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
108 {
109  Q_OBJECT
110  public:
111  QgsSvgSelectorDialog( QWidget* parent = 0, Qt::WindowFlags fl = QgisGui::ModalDialogFlags,
112  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
113  Qt::Orientation orientation = Qt::Horizontal );
115 
117  QVBoxLayout* layout() { return mLayout; }
118 
120  QDialogButtonBox* buttonBox() { return mButtonBox; }
121 
123  QgsSvgSelectorWidget* svgSelector() { return mSvgSelector; }
124 
125  protected:
126  QVBoxLayout* mLayout;
127  QDialogButtonBox* mButtonBox;
129 };
130 
131 #endif // QGSSVGSELECTORWIDGET_H