QGIS API Documentation  2.99.0-Master (0a63d1f)
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 
22 #include "qgisgui.h"
23 #include <QAbstractListModel>
24 #include <QDialog>
25 #include <QDialogButtonBox>
26 #include <QLayout>
27 #include <QStandardItemModel>
28 #include <QWidget>
29 #include <QThread>
30 #include <QElapsedTimer>
31 #include "qgis_gui.h"
32 
33 class QCheckBox;
34 class QLayout;
35 class QLineEdit;
36 class QListView;
37 class QPushButton;
38 class QTreeView;
39 
41 
47 class GUI_EXPORT QgsSvgSelectorLoader : public QThread
48 {
49  Q_OBJECT
50 
51  public:
52 
56  QgsSvgSelectorLoader( QObject* parent = nullptr );
57 
58  ~QgsSvgSelectorLoader();
59 
64  virtual void run() override;
65 
69  virtual void stop();
70 
74  void setPath( const QString& path )
75  {
76  mPath = path;
77  }
78 
79  signals:
80 
85  void foundSvgs( QStringList svgs );
86 
87  private:
88 
89  QString mPath;
90  bool mCancelled;
91  QStringList mQueuedSvgs;
92 
93  QElapsedTimer mTimer;
94  int mTimerThreshold;
95  QSet< QString > mTraversedPaths;
96 
97  void loadPath( const QString& path );
98  void loadImages( const QString& path );
99 
100 };
101 
107 class GUI_EXPORT QgsSvgGroupLoader : public QThread
108 {
109  Q_OBJECT
110 
111  public:
112 
116  QgsSvgGroupLoader( QObject* parent = nullptr );
117 
118  ~QgsSvgGroupLoader();
119 
123  virtual void run() override;
124 
128  virtual void stop();
129 
133  void setParentPaths( const QStringList& parentPaths )
134  {
135  mParentPaths = parentPaths;
136  }
137 
138  signals:
139 
144  void foundPath( const QString& parentPath, const QString& path );
145 
146  private:
147 
148  QStringList mParentPaths;
149  bool mCancelled;
150  QSet< QString > mTraversedPaths;
151 
152  void loadGroup( const QString& parentPath );
153 
154 };
155 
158 
165 class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
166 {
167  Q_OBJECT
168 
169  public:
170 
175  QgsSvgSelectorListModel( QObject* parent );
176 
181  QgsSvgSelectorListModel( QObject* parent, const QString& path );
182 
183  int rowCount( const QModelIndex & parent = QModelIndex() ) const override;
184  QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const override;
185 
186  protected:
187  QStringList mSvgFiles;
188 
189  private:
190  QPixmap createPreview( const QString& entry ) const;
191  QgsSvgSelectorLoader* mSvgLoader;
192 
193  private slots:
194 
198  void addSvgs( const QStringList& svgs );
199 
200 };
201 
202 
209 class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
210 {
211  Q_OBJECT
212 
213  public:
214  QgsSvgSelectorGroupsModel( QObject* parent );
216 
217  private:
218  QgsSvgGroupLoader* mLoader;
219  QHash< QString, QStandardItem* > mPathItemHash;
220 
221  private slots:
222 
223  void addPath( const QString& parentPath, const QString& path );
224 };
225 
229 class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
230 {
231  Q_OBJECT
232 
233  public:
234  QgsSvgSelectorWidget( QWidget* parent = nullptr );
236 
237  static QgsSvgSelectorWidget* create( QWidget* parent = nullptr ) { return new QgsSvgSelectorWidget( parent ); }
238 
239  QString currentSvgPath() const;
240  QString currentSvgPathToName() const;
241 
242  QTreeView* groupsTreeView() { return mGroupsTreeView; }
243  QListView* imagesListView() { return mImagesListView; }
244  QLineEdit* filePathLineEdit() { return mFileLineEdit; }
245  QPushButton* filePathButton() { return mFilePushButton; }
246  QCheckBox* relativePathCheckbox() { return mRelativePathChkBx; }
247  QLayout* selectorLayout() { return this->layout(); }
248 
249  public slots:
251  void setSvgPath( const QString& svgPath );
252 
253  signals:
254  void svgSelected( const QString& path );
255 
256  protected:
257  void populateList();
258 
259  private slots:
260  void populateIcons( const QModelIndex& idx );
261  void svgSelectionChanged( const QModelIndex& idx );
262  void updateCurrentSvgPath( const QString& svgPath );
263 
264  void on_mFilePushButton_clicked();
265  void updateLineEditFeedback( bool ok, const QString& tip = QString() );
266  void on_mFileLineEdit_textChanged( const QString& text );
267 
268  private:
269  QString mCurrentSvgPath; // always stored as absolute path
270 
271 };
272 
276 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
277 {
278  Q_OBJECT
279  public:
280 
284  QgsSvgSelectorDialog( QWidget* parent = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags,
285  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
286  Qt::Orientation orientation = Qt::Horizontal );
288 
290  QVBoxLayout* layout() { return mLayout; }
291 
293  QDialogButtonBox* buttonBox() { return mButtonBox; }
294 
296  QgsSvgSelectorWidget* svgSelector() { return mSvgSelector; }
297 
298  protected:
299  QVBoxLayout* mLayout;
300  QDialogButtonBox* mButtonBox;
302 };
303 
304 #endif // QGSSVGSELECTORWIDGET_H
QgsSvgSelectorWidget * mSvgSelector
static const Qt::WindowFlags ModalDialogFlags
Definition: qgisgui.h:51
static unsigned index
static QgsSvgSelectorWidget * create(QWidget *parent=nullptr)
A model for displaying SVG files with a preview icon.
QDialogButtonBox * buttonBox()
Returns the button box.
QPushButton * filePathButton()
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
QDialogButtonBox * mButtonBox
A model for displaying SVG search paths.
QgsSvgSelectorWidget * svgSelector()
Returns pointer to the embedded SVG selector widget.
QCheckBox * relativePathCheckbox()