QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
22#include "qgis_gui.h"
23#include "qgis_sip.h"
24#include "qgsguiutils.h"
25#include "qgsproperty.h"
26
27#include <QAbstractListModel>
28#include <QDialog>
29#include <QDialogButtonBox>
30#include <QElapsedTimer>
31#include <QItemDelegate>
32#include <QLayout>
33#include <QSortFilterProxyModel>
34#include <QStandardItemModel>
35#include <QThread>
36#include <QWidget>
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 )
111 , property( property )
112 {}
113
114 QString name;
115 QgsProperty property;
116 };
117
118 QList<Parameter> mParameters;
119 QgsVectorLayer *mLayer = nullptr;
120 const QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
121};
122
129class GUI_EXPORT QgsSvgParameterValueDelegate : public QItemDelegate
130{
131 Q_OBJECT
132
133 public:
134 QgsSvgParameterValueDelegate( QObject *parent = nullptr )
135 : QItemDelegate( parent )
136 {}
137
138 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
139 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
140 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
141 void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
142};
143
144
150class GUI_EXPORT QgsSvgSelectorLoader : public QThread
151{
152 Q_OBJECT
153
154 public:
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 ) { mPath = path; }
181
182 signals:
183
189 void foundSvgs( QStringList svgs );
190
191 private:
192 QString mPath;
193 bool mCanceled = false;
194 QStringList mQueuedSvgs;
195
196 QElapsedTimer mTimer;
197 int mTimerThreshold = 0;
198 QSet<QString> mTraversedPaths;
199
200 void loadPath( const QString &path );
201 void loadImages( const QString &path );
202};
203
209class GUI_EXPORT QgsSvgGroupLoader : public QThread
210{
211 Q_OBJECT
212
213 public:
218 QgsSvgGroupLoader( QObject *parent = nullptr );
219
220 ~QgsSvgGroupLoader() override;
221
226 void run() override;
227
232 virtual void stop();
233
238 void setParentPaths( const QStringList &parentPaths ) { mParentPaths = parentPaths; }
239
240 signals:
241
247 void foundPath( const QString &parentPath, const QString &path );
248
249 private:
250 QStringList mParentPaths;
251 bool mCanceled = false;
252 QSet<QString> mTraversedPaths;
253
254 void loadGroup( const QString &parentPath );
255};
256
258#endif
259
269class GUI_EXPORT QgsSvgSelectorFilterModel : public QSortFilterProxyModel
270{
271 Q_OBJECT
272
273 public:
280 QgsSvgSelectorFilterModel( QObject *parent SIP_TRANSFERTHIS, const QString &path = QString(), int iconSize = 30 );
281
282 private:
283 QgsSvgSelectorListModel *mModel = nullptr;
284};
285
295class GUI_EXPORT QgsSvgSelectorListModel : public QAbstractListModel
296{
297 Q_OBJECT
298
299 public:
306 QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, int iconSize = 30 );
307
314 QgsSvgSelectorListModel( QObject *parent SIP_TRANSFERTHIS, const QString &path, int iconSize = 30 );
315
316 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
317 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
318
319 protected:
320 QStringList mSvgFiles;
321
322 private:
323 QPixmap createPreview( const QString &entry ) const;
324 QgsSvgSelectorLoader *mSvgLoader = nullptr;
325
326 int mIconSize = 30;
327
328 private slots:
329
334 void addSvgs( const QStringList &svgs );
335
337};
338
339
349class GUI_EXPORT QgsSvgSelectorGroupsModel : public QStandardItemModel
350{
351 Q_OBJECT
352
353 public:
356
357 private:
358 QgsSvgGroupLoader *mLoader = nullptr;
359 QHash<QString, QStandardItem *> mPathItemHash;
360
361 private slots:
362
363 void addPath( const QString &parentPath, const QString &path );
364};
365
372class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
373{
374 Q_OBJECT
375
376 public:
378 QgsSvgSelectorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
379
384 void initParametersModel( const QgsExpressionContextGenerator *generator, QgsVectorLayer *layer = nullptr );
385
386 QString currentSvgPath() const;
387
392 QgsPictureSourceLineEditBase *sourceLineEdit() const { return mSourceLineEdit; }
393
398 void setAllowParameters( bool allow );
399
405 Q_DECL_DEPRECATED bool allowParamerters() const SIP_DEPRECATED { return mAllowParameters; } // spellok
406
411 bool allowParameters() const { return mAllowParameters; }
412
417 void setBrowserVisible( bool visible );
418
423 bool browserVisible() const { return mBrowserVisible; }
424
429 QgsPropertyOverrideButton *propertyOverrideToolButton() const;
430
431 public slots:
433 void setSvgPath( const QString &svgPath );
434
439 void setSvgParameters( const QMap<QString, QgsProperty> &parameters );
440
441 signals:
442
446 void svgSelected( const QString &path );
447
452 void svgParametersChanged( const QMap<QString, QgsProperty> &parameters );
453
454 protected:
455 void populateList();
456
457 private slots:
458 void populateIcons( const QModelIndex &idx );
459 void svgSelectionChanged( const QModelIndex &idx );
460 void updateCurrentSvgPath( const QString &svgPath );
461 void svgSourceChanged( const QString &text );
462
463 private:
464 int mIconSize = 30;
465 QString mCurrentSvgPath;
466 bool mAllowParameters = false;
467 bool mBrowserVisible = true;
468 QgsSvgParametersModel *mParametersModel = nullptr;
469};
470
476class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
477{
478 Q_OBJECT
479 public:
484 QWidget *parent SIP_TRANSFERTHIS = nullptr,
485 Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
486 QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
487 Qt::Orientation orientation = Qt::Horizontal
488 );
489
492
493 protected:
494 QVBoxLayout *mLayout = nullptr;
495 QDialogButtonBox *mButtonBox = 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.
QgsSvgSelectorDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Close|QDialogButtonBox::Ok, Qt::Orientation orientation=Qt::Horizontal)
Constructor for QgsSvgSelectorDialog.
QgsSvgSelectorWidget * svgSelector()
Returns pointer to the embedded SVG selector widget.
QDialogButtonBox * mButtonBox
QgsSvgSelectorWidget * mSvgSelector
QgsSvgSelectorFilterModel(QObject *parent, const QString &path=QString(), int iconSize=30)
Constructor for creating a model for SVG files in a specific path.
A model for displaying SVG files with a preview icon.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QgsSvgSelectorListModel(QObject *parent, int iconSize=30)
Constructor for QgsSvgSelectorListModel.
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.
void initParametersModel(const QgsExpressionContextGenerator *generator, QgsVectorLayer *layer=nullptr)
Initialize the parameters model so the context and the layer are referenced.
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.
QgsSvgSelectorWidget(QWidget *parent=nullptr)
Constructor for QgsSvgSelectorWidget.
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 dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52