QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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_sip.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 
269  QgsSvgSourceLineEdit *sourceLineEdit() const {return mSvgSourceLineEdit;}
270 
271  public slots:
273  void setSvgPath( const QString &svgPath );
274 
275  signals:
276  void svgSelected( const QString &path );
277 
278  protected:
279  void populateList();
280 
281  private slots:
282  void populateIcons( const QModelIndex &idx );
283  void svgSelectionChanged( const QModelIndex &idx );
284  void updateCurrentSvgPath( const QString &svgPath );
285  void svgSourceChanged( const QString &text );
286 
287  private:
288 
289  int mIconSize = 30;
290 
291  QString mCurrentSvgPath;
292 
293 };
294 
299 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
300 {
301  Q_OBJECT
302  public:
303 
307  QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
308  Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
309  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
310  Qt::Orientation orientation = Qt::Horizontal );
311 
313  QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
314 
315  protected:
316  QVBoxLayout *mLayout = nullptr;
317  QDialogButtonBox *mButtonBox = nullptr;
318  QgsSvgSelectorWidget *mSvgSelector = nullptr;
319 };
320 
321 #endif // QGSSVGSELECTORWIDGET_H
QgsSvgSelectorDialog
Definition: qgssvgselectorwidget.h:300
QgsGuiUtils::iconSize
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
Definition: qgsguiutils.cpp:250
QgsSvgSelectorDialog::svgSelector
QgsSvgSelectorWidget * svgSelector()
Returns pointer to the embedded SVG selector widget.
Definition: qgssvgselectorwidget.h:313
QgsSvgSelectorListModel::mSvgFiles
QStringList mSvgFiles
Definition: qgssvgselectorwidget.h:207
QgsSvgSelectorWidget::sourceLineEdit
QgsSvgSourceLineEdit * sourceLineEdit() const
Returns the source line edit.
Definition: qgssvgselectorwidget.h:269
qgis_sip.h
QgsSvgSelectorListModel
A model for displaying SVG files with a preview icon.
Definition: qgssvgselectorwidget.h:182
QgsSvgSelectorWidget::svgSelected
void svgSelected(const QString &path)
QgsSvgSelectorGroupsModel
A model for displaying SVG search paths.
Definition: qgssvgselectorwidget.h:234
QgsSvgSelectorWidget
Definition: qgssvgselectorwidget.h:255
QgsSvgSourceLineEdit
A line edit widget with toolbutton for setting an SVG image path.
Definition: qgsfilecontentsourcelineedit.h:191
qgsguiutils.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53