QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
148class GUI_EXPORT QgsSvgSelectorLoader : public QThread
149{
150 Q_OBJECT
151
152 public:
157 QgsSvgSelectorLoader( QObject *parent = nullptr );
158
159 ~QgsSvgSelectorLoader() override;
160
166 void run() override;
167
172 virtual void stop();
173
178 void setPath( const QString &path )
179 {
180 mPath = path;
181 }
182
183 signals:
184
190 void foundSvgs( QStringList svgs );
191
192 private:
193 QString mPath;
194 bool mCanceled = false;
195 QStringList mQueuedSvgs;
196
197 QElapsedTimer mTimer;
198 int mTimerThreshold = 0;
199 QSet<QString> mTraversedPaths;
200
201 void loadPath( const QString &path );
202 void loadImages( const QString &path );
203};
204
210class GUI_EXPORT QgsSvgGroupLoader : public QThread
211{
212 Q_OBJECT
213
214 public:
219 QgsSvgGroupLoader( QObject *parent = nullptr );
220
221 ~QgsSvgGroupLoader() override;
222
227 void run() override;
228
233 virtual void stop();
234
239 void setParentPaths( const QStringList &parentPaths )
240 {
241 mParentPaths = parentPaths;
242 }
243
244 signals:
245
251 void foundPath( const QString &parentPath, const QString &path );
252
253 private:
254 QStringList mParentPaths;
255 bool mCanceled = false;
256 QSet<QString> mTraversedPaths;
257
258 void loadGroup( const QString &parentPath );
259};
260
262#endif
263
272class GUI_EXPORT QgsSvgSelectorFilterModel : public QSortFilterProxyModel
273{
274 Q_OBJECT
275
276 public:
283 QgsSvgSelectorFilterModel( QObject *parent SIP_TRANSFERTHIS, const QString &path = QString(), int iconSize = 30 );
284
285 private:
286 QgsSvgSelectorListModel *mModel = nullptr;
287};
288
296class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
297{
298 Q_OBJECT
299
300 public:
307 QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, int iconSize = 30 );
308
315 QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, const QString &path, int iconSize = 30 );
316
317 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
318 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
319
320 protected:
321 QStringList mSvgFiles;
322
323 private:
324 QPixmap createPreview( const QString &entry ) const;
325 QgsSvgSelectorLoader *mSvgLoader = nullptr;
326
327 int mIconSize = 30;
328
329 private slots:
330
335 void addSvgs( const QStringList &svgs );
336
337 friend class TestQgsSvgSelectorWidget;
338};
339
340
348class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
349{
350 Q_OBJECT
351
352 public:
355
356 private:
357 QgsSvgGroupLoader *mLoader = nullptr;
358 QHash<QString, QStandardItem *> mPathItemHash;
359
360 private slots:
361
362 void addPath( const QString &parentPath, const QString &path );
363};
364
371class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
372{
373 Q_OBJECT
374
375 public:
377 QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
378
383 void initParametersModel( const QgsExpressionContextGenerator *generator, QgsVectorLayer *layer = nullptr );
384
385 QString currentSvgPath() const;
386
391 QgsPictureSourceLineEditBase *sourceLineEdit() const { return mSourceLineEdit; }
392
397 void setAllowParameters( bool allow );
398
404 Q_DECL_DEPRECATED bool allowParamerters() const SIP_DEPRECATED { return mAllowParameters; } // spellok
405
410 bool allowParameters() const { return mAllowParameters; }
411
416 void setBrowserVisible( bool visible );
417
422 bool browserVisible() const { return mBrowserVisible; }
423
428 QgsPropertyOverrideButton *propertyOverrideToolButton() const;
429
430 public slots:
432 void setSvgPath( const QString &svgPath );
433
438 void setSvgParameters( const QMap<QString, QgsProperty> &parameters );
439
440 signals:
441
445 void svgSelected( const QString &path );
446
451 void svgParametersChanged( const QMap<QString, QgsProperty> &parameters );
452
453 protected:
454 void populateList();
455
456 private slots:
457 void populateIcons( const QModelIndex &idx );
458 void svgSelectionChanged( const QModelIndex &idx );
459 void updateCurrentSvgPath( const QString &svgPath );
460 void svgSourceChanged( const QString &text );
461
462 private:
463 int mIconSize = 30;
464 QString mCurrentSvgPath;
465 bool mAllowParameters = false;
466 bool mBrowserVisible = true;
467 QgsSvgParametersModel *mParametersModel = nullptr;
468};
469
474class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
475{
476 Q_OBJECT
477 public:
481 QgsSvgSelectorDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok, Qt::Orientation orientation = Qt::Horizontal );
482
484 QgsSvgSelectorWidget *svgSelector() { return mSvgSelector; }
485
486 protected:
487 QVBoxLayout *mLayout = nullptr;
488 QDialogButtonBox *mButtonBox = nullptr;
489 QgsSvgSelectorWidget *mSvgSelector = nullptr;
490};
491
492#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