QGIS API Documentation  2.99.0-Master (7d4f81d)
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 
50 class GUI_EXPORT QgsSvgSelectorLoader : public QThread
51 {
52  Q_OBJECT
53 
54  public:
55 
59  QgsSvgSelectorLoader( QObject *parent = nullptr );
60 
61  ~QgsSvgSelectorLoader();
62 
67  virtual void run() override;
68 
72  virtual void stop();
73 
77  void setPath( const QString &path )
78  {
79  mPath = path;
80  }
81 
82  signals:
83 
88  void foundSvgs( QStringList svgs );
89 
90  private:
91 
92  QString mPath;
93  bool mCanceled;
94  QStringList mQueuedSvgs;
95 
96  QElapsedTimer mTimer;
97  int mTimerThreshold;
98  QSet< QString > mTraversedPaths;
99 
100  void loadPath( const QString &path );
101  void loadImages( const QString &path );
102 
103 };
104 
110 class GUI_EXPORT QgsSvgGroupLoader : public QThread
111 {
112  Q_OBJECT
113 
114  public:
115 
119  QgsSvgGroupLoader( QObject *parent = nullptr );
120 
121  ~QgsSvgGroupLoader();
122 
126  virtual void run() override;
127 
131  virtual void stop();
132 
136  void setParentPaths( const QStringList &parentPaths )
137  {
138  mParentPaths = parentPaths;
139  }
140 
141  signals:
142 
147  void foundPath( const QString &parentPath, const QString &path );
148 
149  private:
150 
151  QStringList mParentPaths;
152  bool mCanceled;
153  QSet< QString > mTraversedPaths;
154 
155  void loadGroup( const QString &parentPath );
156 
157 };
158 
160 #endif
161 
168 class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
169 {
170  Q_OBJECT
171 
172  public:
173 
179  QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, int iconSize = 30 );
180 
186  QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, const QString &path, int iconSize = 30 );
187 
188  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
189  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
190 
191  protected:
192  QStringList mSvgFiles;
193 
194  private:
195  QPixmap createPreview( const QString &entry ) const;
196  QgsSvgSelectorLoader *mSvgLoader = nullptr;
197 
198  int mIconSize = 30;
199 
200  private slots:
201 
205  void addSvgs( const QStringList &svgs );
206 
207 };
208 
209 
216 class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
217 {
218  Q_OBJECT
219 
220  public:
221  QgsSvgSelectorGroupsModel( QObject *parent SIP_TRANSFERTHIS );
223 
224  private:
225  QgsSvgGroupLoader *mLoader = nullptr;
226  QHash< QString, QStandardItem * > mPathItemHash;
227 
228  private slots:
229 
230  void addPath( const QString &parentPath, const QString &path );
231 };
232 
236 class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
237 {
238  Q_OBJECT
239 
240  public:
241  QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = 0 );
243 
244  QString currentSvgPath() const;
245 
246  public slots:
248  void setSvgPath( const QString &svgPath );
249 
250  signals:
251  void svgSelected( const QString &path );
252 
253  protected:
254  void populateList();
255 
256  private slots:
257  void populateIcons( const QModelIndex &idx );
258  void svgSelectionChanged( const QModelIndex &idx );
259  void updateCurrentSvgPath( const QString &svgPath );
260 
261  void on_mFilePushButton_clicked();
262  void updateLineEditFeedback( bool ok, const QString &tip = QString() );
263  void on_mFileLineEdit_textChanged( const QString &text );
264 
265  private:
266 
267  int mIconSize = 30;
268 
269  QString mCurrentSvgPath;
270 
271 };
272 
276 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
277 {
278  Q_OBJECT
279  public:
280 
284  QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
285  Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
286  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
287  Qt::Orientation orientation = Qt::Horizontal );
289 
291  QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
292 
293  protected:
294  QVBoxLayout *mLayout = nullptr;
295  QDialogButtonBox *mButtonBox = nullptr;
296  QgsSvgSelectorWidget *mSvgSelector = nullptr;
297 };
298 
299 #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.