QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #include <QAbstractListModel>
24 #include <QDialog>
25 #include <QDialogButtonBox>
26 #include <QLayout>
27 #include <QStandardItemModel>
28 #include <QWidget>
29 #include <QThread>
30 #include <QElapsedTimer>
31 
32 class QCheckBox;
33 class QLayout;
34 class QLineEdit;
35 class QListView;
36 class QPushButton;
37 class QTreeView;
38 
40 
46 class GUI_EXPORT QgsSvgSelectorLoader : public QThread
47 {
48  Q_OBJECT
49 
50  public:
51 
55  QgsSvgSelectorLoader( QObject* parent = nullptr );
56 
57  ~QgsSvgSelectorLoader();
58 
63  virtual void run() override;
64 
68  virtual void stop();
69 
73  void setPath( const QString& path )
74  {
75  mPath = path;
76  }
77 
78  signals:
79 
84  void foundSvgs( QStringList svgs );
85 
86  private:
87 
88  QString mPath;
89  bool mCancelled;
90  QStringList mQueuedSvgs;
91 
92  QElapsedTimer mTimer;
93  int mTimerThreshold;
94  QSet< QString > mTraversedPaths;
95 
96  void loadPath( const QString& path );
97  void loadImages( const QString& path );
98 
99 };
100 
106 class GUI_EXPORT QgsSvgGroupLoader : public QThread
107 {
108  Q_OBJECT
109 
110  public:
111 
115  QgsSvgGroupLoader( QObject* parent = nullptr );
116 
117  ~QgsSvgGroupLoader();
118 
122  virtual void run() override;
123 
127  virtual void stop();
128 
132  void setParentPaths( const QStringList& parentPaths )
133  {
134  mParentPaths = parentPaths;
135  }
136 
137  signals:
138 
143  void foundPath( const QString& parentPath, const QString& path );
144 
145  private:
146 
147  QStringList mParentPaths;
148  bool mCancelled;
149  QSet< QString > mTraversedPaths;
150 
151  void loadGroup( const QString& parentPath );
152 
153 };
154 
157 
165 {
166  Q_OBJECT
167 
168  public:
169 
174  QgsSvgSelectorListModel( QObject* parent );
175 
180  QgsSvgSelectorListModel( QObject* parent, const QString& path );
181 
182  int rowCount( const QModelIndex & parent = QModelIndex() ) const override;
183  QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const override;
184 
185  protected:
187 
188  private:
189  QPixmap createPreview( const QString& entry ) const;
190  QgsSvgSelectorLoader* mSvgLoader;
191 
192  private slots:
193 
197  void addSvgs( const QStringList& svgs );
198 
199 };
200 
201 
209 {
210  Q_OBJECT
211 
212  public:
215 
216  private:
217  QgsSvgGroupLoader* mLoader;
218  QHash< QString, QStandardItem* > mPathItemHash;
219 
220  private slots:
221 
222  void addPath( const QString& parentPath, const QString& path );
223 };
224 
228 class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
229 {
230  Q_OBJECT
231 
232  public:
233  QgsSvgSelectorWidget( QWidget* parent = nullptr );
235 
236  static QgsSvgSelectorWidget* create( QWidget* parent = nullptr ) { return new QgsSvgSelectorWidget( parent ); }
237 
238  QString currentSvgPath() const;
239  QString currentSvgPathToName() const;
240 
241  QTreeView* groupsTreeView() { return mGroupsTreeView; }
242  QListView* imagesListView() { return mImagesListView; }
243  QLineEdit* filePathLineEdit() { return mFileLineEdit; }
244  QPushButton* filePathButton() { return mFilePushButton; }
245  QCheckBox* relativePathCheckbox() { return mRelativePathChkBx; }
246  QLayout* selectorLayout() { return this->layout(); }
247 
248  public slots:
250  void setSvgPath( const QString& svgPath );
251 
252  signals:
253  void svgSelected( const QString& path );
254 
255  protected:
256  void populateList();
257 
258  private slots:
259  void populateIcons( const QModelIndex& idx );
260  void svgSelectionChanged( const QModelIndex& idx );
261  void updateCurrentSvgPath( const QString& svgPath );
262 
263  void on_mFilePushButton_clicked();
264  void updateLineEditFeedback( bool ok, const QString& tip = QString() );
265  void on_mFileLineEdit_textChanged( const QString& text );
266 
267  private:
268  QString mCurrentSvgPath; // always stored as absolute path
269 
270 };
271 
275 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
276 {
277  Q_OBJECT
278  public:
280  const QDialogButtonBox::StandardButtons& buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
281  Qt::Orientation orientation = Qt::Horizontal );
283 
285  QVBoxLayout* layout() { return mLayout; }
286 
288  QDialogButtonBox* buttonBox() { return mButtonBox; }
289 
291  QgsSvgSelectorWidget* svgSelector() { return mSvgSelector; }
292 
293  protected:
297 };
298 
299 #endif // QGSSVGSELECTORWIDGET_H
QLayout * layout() const
QgsSvgSelectorWidget * mSvgSelector
static const Qt::WindowFlags ModalDialogFlags
Definition: qgisgui.h:50
static unsigned index
virtual int rowCount(const QModelIndex &parent) const=0
static QgsSvgSelectorWidget * create(QWidget *parent=nullptr)
A model for displaying SVG files with a preview icon.
QDialogButtonBox * buttonBox()
Returns the button box.
QPushButton * filePathButton()
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
QDialogButtonBox * mButtonBox
virtual QVariant data(const QModelIndex &index, int role) const=0
virtual void run()
A model for displaying SVG search paths.
QgsSvgSelectorWidget * svgSelector()
Returns pointer to the embedded SVG selector widget.
typedef StandardButtons
QCheckBox * relativePathCheckbox()
typedef WindowFlags