QGIS API Documentation  2.99.0-Master (dcec6bb)
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 
178  QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS );
179 
184  QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, const QString &path );
185 
186  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
187  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
188 
189  protected:
190  QStringList mSvgFiles;
191 
192  private:
193  QPixmap createPreview( const QString &entry ) const;
194  QgsSvgSelectorLoader *mSvgLoader = nullptr;
195 
196  private slots:
197 
201  void addSvgs( const QStringList &svgs );
202 
203 };
204 
205 
212 class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
213 {
214  Q_OBJECT
215 
216  public:
217  QgsSvgSelectorGroupsModel( QObject *parent SIP_TRANSFERTHIS );
219 
220  private:
221  QgsSvgGroupLoader *mLoader = nullptr;
222  QHash< QString, QStandardItem * > mPathItemHash;
223 
224  private slots:
225 
226  void addPath( const QString &parentPath, const QString &path );
227 };
228 
232 class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
233 {
234  Q_OBJECT
235 
236  public:
237  QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = 0 );
239 
240  QString currentSvgPath() const;
241 
242  public slots:
244  void setSvgPath( const QString &svgPath );
245 
246  signals:
247  void svgSelected( const QString &path );
248 
249  protected:
250  void populateList();
251 
252  private slots:
253  void populateIcons( const QModelIndex &idx );
254  void svgSelectionChanged( const QModelIndex &idx );
255  void updateCurrentSvgPath( const QString &svgPath );
256 
257  void on_mFilePushButton_clicked();
258  void updateLineEditFeedback( bool ok, const QString &tip = QString() );
259  void on_mFileLineEdit_textChanged( const QString &text );
260 
261  private:
262  QString mCurrentSvgPath;
263 
264 };
265 
269 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
270 {
271  Q_OBJECT
272  public:
273 
277  QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
278  Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
279  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
280  Qt::Orientation orientation = Qt::Horizontal );
282 
284  QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
285 
286  protected:
287  QVBoxLayout *mLayout = nullptr;
288  QDialogButtonBox *mButtonBox = nullptr;
289  QgsSvgSelectorWidget *mSvgSelector = nullptr;
290 };
291 
292 #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.