QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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 <QItemDelegate>
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 QItemDelegate
128{
129 Q_OBJECT
130
131 public:
132 QgsSvgParameterValueDelegate( QObject *parent = nullptr )
133 : QItemDelegate( 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
149class GUI_EXPORT QgsSvgSelectorLoader : public QThread
150{
151 Q_OBJECT
152
153 public:
154
159 QgsSvgSelectorLoader( QObject *parent = nullptr );
160
161 ~QgsSvgSelectorLoader() override;
162
168 void run() override;
169
174 virtual void stop();
175
180 void setPath( const QString &path )
181 {
182 mPath = path;
183 }
184
185 signals:
186
192 void foundSvgs( QStringList svgs );
193
194 private:
195
196 QString mPath;
197 bool mCanceled = false;
198 QStringList mQueuedSvgs;
199
200 QElapsedTimer mTimer;
201 int mTimerThreshold = 0;
202 QSet< QString > mTraversedPaths;
203
204 void loadPath( const QString &path );
205 void loadImages( const QString &path );
206
207};
208
214class GUI_EXPORT QgsSvgGroupLoader : public QThread
215{
216 Q_OBJECT
217
218 public:
219
224 QgsSvgGroupLoader( QObject *parent = nullptr );
225
226 ~QgsSvgGroupLoader() override;
227
232 void run() override;
233
238 virtual void stop();
239
244 void setParentPaths( const QStringList &parentPaths )
245 {
246 mParentPaths = parentPaths;
247 }
248
249 signals:
250
256 void foundPath( const QString &parentPath, const QString &path );
257
258 private:
259
260 QStringList mParentPaths;
261 bool mCanceled = false;
262 QSet< QString > mTraversedPaths;
263
264 void loadGroup( const QString &parentPath );
265
266};
267
269#endif
270
279class GUI_EXPORT QgsSvgSelectorFilterModel : public QSortFilterProxyModel
280{
281 Q_OBJECT
282
283 public:
284
291 QgsSvgSelectorFilterModel( QObject *parent SIP_TRANSFERTHIS, const QString &path = QString(), int iconSize = 30 );
292
293 private:
294 QgsSvgSelectorListModel *mModel = nullptr;
295};
296
304class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
305{
306 Q_OBJECT
307
308 public:
309
316 QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, int iconSize = 30 );
317
324 QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, const QString &path, int iconSize = 30 );
325
326 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
327 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
328
329 protected:
330 QStringList mSvgFiles;
331
332 private:
333 QPixmap createPreview( const QString &entry ) const;
334 QgsSvgSelectorLoader *mSvgLoader = nullptr;
335
336 int mIconSize = 30;
337
338 private slots:
339
344 void addSvgs( const QStringList &svgs );
345
346 friend class TestQgsSvgSelectorWidget;
347};
348
349
357class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
358{
359 Q_OBJECT
360
361 public:
364
365 private:
366 QgsSvgGroupLoader *mLoader = nullptr;
367 QHash< QString, QStandardItem * > mPathItemHash;
368
369 private slots:
370
371 void addPath( const QString &parentPath, const QString &path );
372};
373
380class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
381{
382 Q_OBJECT
383
384 public:
385
387 QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
388
393 void initParametersModel( const QgsExpressionContextGenerator *generator, QgsVectorLayer *layer = nullptr );
394
395 QString currentSvgPath() const;
396
401 QgsPictureSourceLineEditBase *sourceLineEdit() const {return mSourceLineEdit;}
402
407 void setAllowParameters( bool allow );
408
414 Q_DECL_DEPRECATED bool allowParamerters() const SIP_DEPRECATED {return mAllowParameters;} // spellok
415
420 bool allowParameters() const {return mAllowParameters;}
421
426 void setBrowserVisible( bool visible );
427
432 bool browserVisible() const {return mBrowserVisible;}
433
438 QgsPropertyOverrideButton *propertyOverrideToolButton() const;
439
440 public slots:
442 void setSvgPath( const QString &svgPath );
443
448 void setSvgParameters( const QMap<QString, QgsProperty> &parameters );
449
450 signals:
451
455 void svgSelected( const QString &path );
456
461 void svgParametersChanged( const QMap<QString, QgsProperty> &parameters );
462
463 protected:
464 void populateList();
465
466 private slots:
467 void populateIcons( const QModelIndex &idx );
468 void svgSelectionChanged( const QModelIndex &idx );
469 void updateCurrentSvgPath( const QString &svgPath );
470 void svgSourceChanged( const QString &text );
471
472 private:
473 int mIconSize = 30;
474 QString mCurrentSvgPath;
475 bool mAllowParameters = false;
476 bool mBrowserVisible = true;
477 QgsSvgParametersModel *mParametersModel = nullptr;
478};
479
484class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
485{
486 Q_OBJECT
487 public:
488
492 QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
493 Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
494 QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
495 Qt::Orientation orientation = Qt::Horizontal );
496
498 QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
499
500 protected:
501 QVBoxLayout *mLayout = nullptr;
502 QDialogButtonBox *mButtonBox = nullptr;
503 QgsSvgSelectorWidget *mSvgSelector = nullptr;
504};
505
506#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.
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.
A widget allowing selection of an SVG file, and configuration of SVG related parameters.
QgsPictureSourceLineEditBase * sourceLineEdit() const
Returns the source line edit.
bool browserVisible() const
Returns if the SVG browser should be visible.
bool allowParameters() const
Returns if the group box to fill parameters is visible.
void svgParametersChanged(const QMap< QString, QgsProperty > &parameters)
Emitted when the parameters have changed.
void svgSelected(const QString &path)
Emitted when an SVG is selected in the widget.
Q_DECL_DEPRECATED bool allowParamerters() const
Returns if the group box to fill parameters is visible.
Represents a vector layer which manages a vector based data sets.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53