QGIS API Documentation 3.29.0-Master (19d7edcfed)
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#include "qgis_gui.h"
23#include "qgsguiutils.h"
24#include "qgsproperty.h"
25
26#include <QSortFilterProxyModel>
27#include <QAbstractListModel>
28#include <QDialog>
29#include <QDialogButtonBox>
30#include <QLayout>
31#include <QStandardItemModel>
32#include <QWidget>
33#include <QThread>
34#include <QElapsedTimer>
35#include <QStyledItemDelegate>
36
37
38class QCheckBox;
39class QLayout;
40class QLineEdit;
41class QListView;
42class QPushButton;
43class QTreeView;
44
48
49
50#ifndef SIP_RUN
52
53
60class GUI_EXPORT QgsSvgParametersModel : public QAbstractTableModel
61{
62 Q_OBJECT
63
64 public:
65 enum class Column : int
66 {
67 NameColumn = 0,
68 ExpressionColumn = 1,
69 };
70
71 QgsSvgParametersModel( QObject *parent = nullptr );
72
74 void setParameters( const QMap<QString, QgsProperty> &parameters );
76 QMap<QString, QgsProperty> parameters() const;
77
79 void removeParameters( const QModelIndexList &indexList );
80
82 void setLayer( QgsVectorLayer *layer );
84 QgsVectorLayer *layer() const {return mLayer;}
85
87 void setExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
89 const QgsExpressionContextGenerator *expressionContextGenerator() const {return mExpressionContextGenerator;}
90
91 int rowCount( const QModelIndex &parent ) const override;
92 int columnCount( const QModelIndex &parent ) const override;
93 QVariant data( const QModelIndex &index, int role ) const override;
94 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
95 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
96 Qt::ItemFlags flags( const QModelIndex &index ) const override;
97
98 public slots:
100 void addParameter();
101
102 signals:
104 void parametersChanged( const QMap<QString, QgsProperty> &parameters );
105
106 private:
107 struct Parameter
108 {
109 Parameter( const QString &name, const QgsProperty &property )
110 : name( name ), property( property ) {}
111
112 QString name;
113 QgsProperty property;
114 };
115
116 QList<Parameter> mParameters;
117 QgsVectorLayer *mLayer = nullptr;
118 const QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
119};
120
127class GUI_EXPORT QgsSvgParameterValueDelegate : public QStyledItemDelegate
128{
129 Q_OBJECT
130
131 public:
132 QgsSvgParameterValueDelegate( QObject *parent = nullptr )
133 : QStyledItemDelegate( parent )
134 {}
135
136 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
137 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
138 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
139 void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
140};
141
142
143
150class GUI_EXPORT QgsSvgSelectorLoader : public QThread
151{
152 Q_OBJECT
153
154 public:
155
160 QgsSvgSelectorLoader( QObject *parent = nullptr );
161
162 ~QgsSvgSelectorLoader() override;
163
169 void run() override;
170
175 virtual void stop();
176
181 void setPath( const QString &path )
182 {
183 mPath = path;
184 }
185
186 signals:
187
193 void foundSvgs( QStringList svgs );
194
195 private:
196
197 QString mPath;
198 bool mCanceled = false;
199 QStringList mQueuedSvgs;
200
201 QElapsedTimer mTimer;
202 int mTimerThreshold = 0;
203 QSet< QString > mTraversedPaths;
204
205 void loadPath( const QString &path );
206 void loadImages( const QString &path );
207
208};
209
216class GUI_EXPORT QgsSvgGroupLoader : public QThread
217{
218 Q_OBJECT
219
220 public:
221
226 QgsSvgGroupLoader( QObject *parent = nullptr );
227
228 ~QgsSvgGroupLoader() override;
229
234 void run() override;
235
240 virtual void stop();
241
246 void setParentPaths( const QStringList &parentPaths )
247 {
248 mParentPaths = parentPaths;
249 }
250
251 signals:
252
258 void foundPath( const QString &parentPath, const QString &path );
259
260 private:
261
262 QStringList mParentPaths;
263 bool mCanceled = false;
264 QSet< QString > mTraversedPaths;
265
266 void loadGroup( const QString &parentPath );
267
268};
269
271#endif
272
281class GUI_EXPORT QgsSvgSelectorFilterModel : public QSortFilterProxyModel
282{
283 Q_OBJECT
284
285 public:
286
293 QgsSvgSelectorFilterModel( QObject *parent SIP_TRANSFERTHIS, const QString &path = QString(), int iconSize = 30 );
294
295 private:
296 QgsSvgSelectorListModel *mModel = nullptr;
297};
298
306class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
307{
308 Q_OBJECT
309
310 public:
311
318 QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, int iconSize = 30 );
319
326 QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, const QString &path, int iconSize = 30 );
327
328 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
329 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
330
331 protected:
332 QStringList mSvgFiles;
333
334 private:
335 QPixmap createPreview( const QString &entry ) const;
336 QgsSvgSelectorLoader *mSvgLoader = nullptr;
337
338 int mIconSize = 30;
339
340 private slots:
341
346 void addSvgs( const QStringList &svgs );
347
348};
349
350
358class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
359{
360 Q_OBJECT
361
362 public:
365
366 private:
367 QgsSvgGroupLoader *mLoader = nullptr;
368 QHash< QString, QStandardItem * > mPathItemHash;
369
370 private slots:
371
372 void addPath( const QString &parentPath, const QString &path );
373};
374
379class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
380{
381 Q_OBJECT
382
383 public:
384
386 QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
387
392 void initParametersModel( const QgsExpressionContextGenerator *generator, QgsVectorLayer *layer = nullptr );
393
394 QString currentSvgPath() const;
395
400 QgsPictureSourceLineEditBase *sourceLineEdit() const {return mSourceLineEdit;}
401
406 void setAllowParameters( bool allow );
407
412 bool allowParamerters() const {return mAllowParameters;}
413
418 void setBrowserVisible( bool visible );
419
424 bool browserVisible() const {return mBrowserVisible;}
425
430 QgsPropertyOverrideButton *propertyOverrideToolButton() const;
431
432 public slots:
434 void setSvgPath( const QString &svgPath );
435
440 void setSvgParameters( const QMap<QString, QgsProperty> &parameters );
441
442 signals:
443 void svgSelected( const QString &path );
444
449 void svgParametersChanged( const QMap<QString, QgsProperty> &parameters );
450
451 protected:
452 void populateList();
453
454 private slots:
455 void populateIcons( const QModelIndex &idx );
456 void svgSelectionChanged( const QModelIndex &idx );
457 void updateCurrentSvgPath( const QString &svgPath );
458 void svgSourceChanged( const QString &text );
459
460 private:
461 int mIconSize = 30;
462 QString mCurrentSvgPath;
463 bool mAllowParameters = false;
464 bool mBrowserVisible = true;
465 QgsSvgParametersModel *mParametersModel = nullptr;
466};
467
472class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
473{
474 Q_OBJECT
475 public:
476
480 QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
481 Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
482 QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
483 Qt::Orientation orientation = Qt::Horizontal );
484
486 QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
487
488 protected:
489 QVBoxLayout *mLayout = nullptr;
490 QDialogButtonBox *mButtonBox = nullptr;
491 QgsSvgSelectorWidget *mSvgSelector = nullptr;
492};
493
494#endif // QGSSVGSELECTORWIDGET_H
Abstract interface for generating an expression context.
A line edit widget with toolbutton for setting a raster image path.
A button for controlling property overrides which may apply to a widget.
A store for object properties.
Definition: qgsproperty.h:230
QgsSvgSelectorWidget * svgSelector()
Returns pointer to the embedded SVG selector widget.
A model for displaying SVG files with a preview icon which can be filtered by file name.
A model for displaying SVG search paths.
A model for displaying SVG files with a preview icon.
QgsPictureSourceLineEditBase * sourceLineEdit() const
Returns the source line edit.
bool browserVisible() const
Returns if the SVG browser should be visible.
void svgParametersChanged(const QMap< QString, QgsProperty > &parameters)
Emitted when the parameters have changed.
void svgSelected(const QString &path)
bool allowParamerters() const
Returns if the group box to fill parameters is visible.
Represents a vector layer which manages a vector based data sets.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53