QGIS API Documentation  2.99.0-Master (d55fa22)
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 
42 
48 class GUI_EXPORT QgsSvgSelectorLoader : public QThread
49 {
50  Q_OBJECT
51 
52  public:
53 
57  QgsSvgSelectorLoader( QObject *parent = nullptr );
58 
59  ~QgsSvgSelectorLoader();
60 
65  virtual void run() override;
66 
70  virtual void stop();
71 
75  void setPath( const QString &path )
76  {
77  mPath = path;
78  }
79 
80  signals:
81 
86  void foundSvgs( QStringList svgs );
87 
88  private:
89 
90  QString mPath;
91  bool mCanceled;
92  QStringList mQueuedSvgs;
93 
94  QElapsedTimer mTimer;
95  int mTimerThreshold;
96  QSet< QString > mTraversedPaths;
97 
98  void loadPath( const QString &path );
99  void loadImages( const QString &path );
100 
101 };
102 
108 class GUI_EXPORT QgsSvgGroupLoader : public QThread
109 {
110  Q_OBJECT
111 
112  public:
113 
117  QgsSvgGroupLoader( QObject *parent = nullptr );
118 
119  ~QgsSvgGroupLoader();
120 
124  virtual void run() override;
125 
129  virtual void stop();
130 
134  void setParentPaths( const QStringList &parentPaths )
135  {
136  mParentPaths = parentPaths;
137  }
138 
139  signals:
140 
145  void foundPath( const QString &parentPath, const QString &path );
146 
147  private:
148 
149  QStringList mParentPaths;
150  bool mCanceled;
151  QSet< QString > mTraversedPaths;
152 
153  void loadGroup( const QString &parentPath );
154 
155 };
156 
159 
166 class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
167 {
168  Q_OBJECT
169 
170  public:
171 
176  QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS );
177 
182  QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, const QString &path );
183 
184  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
185  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
186 
187  protected:
188  QStringList mSvgFiles;
189 
190  private:
191  QPixmap createPreview( const QString &entry ) const;
192  QgsSvgSelectorLoader *mSvgLoader = nullptr;
193 
194  private slots:
195 
199  void addSvgs( const QStringList &svgs );
200 
201 };
202 
203 
210 class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
211 {
212  Q_OBJECT
213 
214  public:
215  QgsSvgSelectorGroupsModel( QObject *parent SIP_TRANSFERTHIS );
217 
218  private:
219  QgsSvgGroupLoader *mLoader = nullptr;
220  QHash< QString, QStandardItem * > mPathItemHash;
221 
222  private slots:
223 
224  void addPath( const QString &parentPath, const QString &path );
225 };
226 
230 class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
231 {
232  Q_OBJECT
233 
234  public:
235  QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = 0 );
237 
238  QString currentSvgPath() const;
239 
240  public slots:
242  void setSvgPath( const QString &svgPath );
243 
244  signals:
245  void svgSelected( const QString &path );
246 
247  protected:
248  void populateList();
249 
250  private slots:
251  void populateIcons( const QModelIndex &idx );
252  void svgSelectionChanged( const QModelIndex &idx );
253  void updateCurrentSvgPath( const QString &svgPath );
254 
255  void on_mFilePushButton_clicked();
256  void updateLineEditFeedback( bool ok, const QString &tip = QString() );
257  void on_mFileLineEdit_textChanged( const QString &text );
258 
259  private:
260  QString mCurrentSvgPath;
261 
262 };
263 
267 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
268 {
269  Q_OBJECT
270  public:
271 
275  QgsSvgSelectorDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
276  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
277  Qt::Orientation orientation = Qt::Horizontal );
279 
281  QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
282 
283  protected:
284  QVBoxLayout *mLayout = nullptr;
285  QDialogButtonBox *mButtonBox = nullptr;
286  QgsSvgSelectorWidget *mSvgSelector = nullptr;
287 };
288 
289 #endif // QGSSVGSELECTORWIDGET_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
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.