QGIS API Documentation  2.99.0-Master (19b062c)
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 qgssymbollayerwidget
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 #include "qgis.h"
22 
23 #include "qgsguiutils.h"
24 #include <QAbstractListModel>
25 #include <QDialog>
26 #include <QDialogButtonBox>
27 #include <QLayout>
28 #include <QStandardItemModel>
29 #include <QWidget>
30 #include <QThread>
31 #include <QElapsedTimer>
32 #include "qgis_gui.h"
33 
34 class QCheckBox;
35 class QLayout;
36 class QLineEdit;
37 class QListView;
38 class QPushButton;
39 class QTreeView;
40 
41 
42 #ifndef SIP_RUN
43 
51 class GUI_EXPORT QgsSvgSelectorLoader : public QThread
52 {
53  Q_OBJECT
54 
55  public:
56 
61  QgsSvgSelectorLoader( QObject *parent = nullptr );
62 
63  ~QgsSvgSelectorLoader();
64 
70  virtual void run() override;
71 
76  virtual void stop();
77 
82  void setPath( const QString &path )
83  {
84  mPath = path;
85  }
86 
87  signals:
88 
94  void foundSvgs( QStringList svgs );
95 
96  private:
97 
98  QString mPath;
99  bool mCanceled = false;
100  QStringList mQueuedSvgs;
101 
102  QElapsedTimer mTimer;
103  int mTimerThreshold = 0;
104  QSet< QString > mTraversedPaths;
105 
106  void loadPath( const QString &path );
107  void loadImages( const QString &path );
108 
109 };
110 
117 class GUI_EXPORT QgsSvgGroupLoader : public QThread
118 {
119  Q_OBJECT
120 
121  public:
122 
127  QgsSvgGroupLoader( QObject *parent = nullptr );
128 
129  ~QgsSvgGroupLoader();
130 
135  virtual void run() override;
136 
141  virtual void stop();
142 
147  void setParentPaths( const QStringList &parentPaths )
148  {
149  mParentPaths = parentPaths;
150  }
151 
152  signals:
153 
159  void foundPath( const QString &parentPath, const QString &path );
160 
161  private:
162 
163  QStringList mParentPaths;
164  bool mCanceled = false;
165  QSet< QString > mTraversedPaths;
166 
167  void loadGroup( const QString &parentPath );
168 
169 };
170 
172 #endif
173 
181 class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
182 {
183  Q_OBJECT
184 
185  public:
186 
193  QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, int iconSize = 30 );
194 
201  QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, const QString &path, int iconSize = 30 );
202 
203  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
204  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
205 
206  protected:
207  QStringList mSvgFiles;
208 
209  private:
210  QPixmap createPreview( const QString &entry ) const;
211  QgsSvgSelectorLoader *mSvgLoader = nullptr;
212 
213  int mIconSize = 30;
214 
215  private slots:
216 
221  void addSvgs( const QStringList &svgs );
222 
223 };
224 
225 
233 class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
234 {
235  Q_OBJECT
236 
237  public:
238  QgsSvgSelectorGroupsModel( QObject *parent SIP_TRANSFERTHIS );
240 
241  private:
242  QgsSvgGroupLoader *mLoader = nullptr;
243  QHash< QString, QStandardItem * > mPathItemHash;
244 
245  private slots:
246 
247  void addPath( const QString &parentPath, const QString &path );
248 };
249 
254 class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
255 {
256  Q_OBJECT
257 
258  public:
259  QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = 0 );
260 
261  QString currentSvgPath() const;
262 
263  public slots:
265  void setSvgPath( const QString &svgPath );
266 
267  signals:
268  void svgSelected( const QString &path );
269 
270  protected:
271  void populateList();
272 
273  private slots:
274  void populateIcons( const QModelIndex &idx );
275  void svgSelectionChanged( const QModelIndex &idx );
276  void updateCurrentSvgPath( const QString &svgPath );
277 
278  void mFilePushButton_clicked();
279  void updateLineEditFeedback( bool ok, const QString &tip = QString() );
280  void mFileLineEdit_textChanged( const QString &text );
281 
282  private:
283 
284  int mIconSize = 30;
285 
286  QString mCurrentSvgPath;
287 
288 };
289 
294 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
295 {
296  Q_OBJECT
297  public:
298 
302  QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
303  Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
304  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
305  Qt::Orientation orientation = Qt::Horizontal );
307 
309  QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
310 
311  protected:
312  QVBoxLayout *mLayout = nullptr;
313  QDialogButtonBox *mButtonBox = nullptr;
314  QgsSvgSelectorWidget *mSvgSelector = nullptr;
315 };
316 
317 #endif // QGSSVGSELECTORWIDGET_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A model for displaying SVG files with a preview icon.
A model for displaying SVG search paths.
QgsSvgSelectorWidget * svgSelector()
Returns pointer to the embedded SVG selector widget.