QGIS API Documentation  3.0.2-Girona (307d082)
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() override;
64 
70  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() override;
130 
135  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 );
239  ~QgsSvgSelectorGroupsModel() override;
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 
261  QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
262 
263  QString currentSvgPath() const;
264 
265  public slots:
267  void setSvgPath( const QString &svgPath );
268 
269  signals:
270  void svgSelected( const QString &path );
271 
272  protected:
273  void populateList();
274 
275  private slots:
276  void populateIcons( const QModelIndex &idx );
277  void svgSelectionChanged( const QModelIndex &idx );
278  void updateCurrentSvgPath( const QString &svgPath );
279 
280  void mFilePushButton_clicked();
281  void updateLineEditFeedback( bool ok, const QString &tip = QString() );
282  void mFileLineEdit_textChanged( const QString &text );
283 
284  private:
285 
286  int mIconSize = 30;
287 
288  QString mCurrentSvgPath;
289 
290 };
291 
296 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
297 {
298  Q_OBJECT
299  public:
300 
304  QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
305  Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
306  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
307  Qt::Orientation orientation = Qt::Horizontal );
308  ~QgsSvgSelectorDialog() override;
309 
311  QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
312 
313  protected:
314  QVBoxLayout *mLayout = nullptr;
315  QDialogButtonBox *mButtonBox = nullptr;
316  QgsSvgSelectorWidget *mSvgSelector = nullptr;
317 };
318 
319 #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.