QGIS API Documentation 3.38.0-Grenoble (exported)
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};
347
348
356class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
357{
358 Q_OBJECT
359
360 public:
363
364 private:
365 QgsSvgGroupLoader *mLoader = nullptr;
366 QHash< QString, QStandardItem * > mPathItemHash;
367
368 private slots:
369
370 void addPath( const QString &parentPath, const QString &path );
371};
372
377class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
378{
379 Q_OBJECT
380
381 public:
382
384 QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
385
390 void initParametersModel( const QgsExpressionContextGenerator *generator, QgsVectorLayer *layer = nullptr );
391
392 QString currentSvgPath() const;
393
398 QgsPictureSourceLineEditBase *sourceLineEdit() const {return mSourceLineEdit;}
399
404 void setAllowParameters( bool allow );
405
411 Q_DECL_DEPRECATED bool allowParamerters() const SIP_DEPRECATED {return mAllowParameters;} // spellok
412
417 bool allowParameters() const {return mAllowParameters;}
418
423 void setBrowserVisible( bool visible );
424
429 bool browserVisible() const {return mBrowserVisible;}
430
435 QgsPropertyOverrideButton *propertyOverrideToolButton() const;
436
437 public slots:
439 void setSvgPath( const QString &svgPath );
440
445 void setSvgParameters( const QMap<QString, QgsProperty> &parameters );
446
447 signals:
448 void svgSelected( const QString &path );
449
454 void svgParametersChanged( const QMap<QString, QgsProperty> &parameters );
455
456 protected:
457 void populateList();
458
459 private slots:
460 void populateIcons( const QModelIndex &idx );
461 void svgSelectionChanged( const QModelIndex &idx );
462 void updateCurrentSvgPath( const QString &svgPath );
463 void svgSourceChanged( const QString &text );
464
465 private:
466 int mIconSize = 30;
467 QString mCurrentSvgPath;
468 bool mAllowParameters = false;
469 bool mBrowserVisible = true;
470 QgsSvgParametersModel *mParametersModel = nullptr;
471};
472
477class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
478{
479 Q_OBJECT
480 public:
481
485 QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
486 Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
487 QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
488 Qt::Orientation orientation = Qt::Horizontal );
489
491 QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
492
493 protected:
494 QVBoxLayout *mLayout = nullptr;
495 QDialogButtonBox *mButtonBox = nullptr;
496 QgsSvgSelectorWidget *mSvgSelector = nullptr;
497};
498
499#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.
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)
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