QGIS API Documentation  2.17.0-Master (eef6f05)
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 qgssymbollayerv2widget
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 "qgisgui.h"
23 
24 #include <QAbstractListModel>
25 #include <QDialog>
26 #include <QDialogButtonBox>
27 #include <QLayout>
28 #include <QStandardItemModel>
29 #include <QWidget>
30 
31 class QCheckBox;
32 class QLayout;
33 class QLineEdit;
34 class QListView;
35 class QPushButton;
36 class QTreeView;
37 
42 {
43  Q_OBJECT
44 
45  public:
47 
48  // Constructor to create model for icons in a specific path
49  QgsSvgSelectorListModel( QObject* parent, const QString& path );
50 
51  int rowCount( const QModelIndex & parent = QModelIndex() ) const override;
52 
53  QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const override;
54 
55  protected:
57 };
58 
63 {
64  Q_OBJECT
65 
66  public:
68 
69  private:
70  void createTree( QStandardItem* &parentGroup );
71 };
72 
76 class GUI_EXPORT QgsSvgSelectorWidget : public QWidget, private Ui::WidgetSvgSelector
77 {
78  Q_OBJECT
79 
80  public:
81  QgsSvgSelectorWidget( QWidget* parent = nullptr );
83 
84  static QgsSvgSelectorWidget* create( QWidget* parent = nullptr ) { return new QgsSvgSelectorWidget( parent ); }
85 
86  QString currentSvgPath() const;
87  QString currentSvgPathToName() const;
88 
89  QTreeView* groupsTreeView() { return mGroupsTreeView; }
90  QListView* imagesListView() { return mImagesListView; }
91  QLineEdit* filePathLineEdit() { return mFileLineEdit; }
92  QPushButton* filePathButton() { return mFilePushButton; }
93  QCheckBox* relativePathCheckbox() { return mRelativePathChkBx; }
94  QLayout* selectorLayout() { return this->layout(); }
95 
96  public slots:
98  void setSvgPath( const QString& svgPath );
99 
100  signals:
101  void svgSelected( const QString& path );
102 
103  protected:
104  void populateList();
105 
106  private slots:
107  void populateIcons( const QModelIndex& idx );
108  void svgSelectionChanged( const QModelIndex& idx );
109  void updateCurrentSvgPath( const QString& svgPath );
110 
111  void on_mFilePushButton_clicked();
112  void updateLineEditFeedback( bool ok, const QString& tip = QString() );
113  void on_mFileLineEdit_textChanged( const QString& text );
114 
115  private:
116  QString mCurrentSvgPath; // always stored as absolute path
117 };
118 
122 class GUI_EXPORT QgsSvgSelectorDialog : public QDialog
123 {
124  Q_OBJECT
125  public:
127  const QDialogButtonBox::StandardButtons& buttons = QDialogButtonBox::Close | QDialogButtonBox::Ok,
128  Qt::Orientation orientation = Qt::Horizontal );
130 
132  QVBoxLayout* layout() { return mLayout; }
133 
135  QDialogButtonBox* buttonBox() { return mButtonBox; }
136 
138  QgsSvgSelectorWidget* svgSelector() { return mSvgSelector; }
139 
140  protected:
144 };
145 
146 #endif // QGSSVGSELECTORWIDGET_H
QLayout * layout() const
QgsSvgSelectorWidget * mSvgSelector
static const Qt::WindowFlags ModalDialogFlags
Definition: qgisgui.h:49
static unsigned index
virtual int rowCount(const QModelIndex &parent) const=0
static QgsSvgSelectorWidget * create(QWidget *parent=nullptr)
QDialogButtonBox * buttonBox()
Returns the button box.
QPushButton * filePathButton()
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
QDialogButtonBox * mButtonBox
virtual QVariant data(const QModelIndex &index, int role) const=0
QgsSvgSelectorWidget * svgSelector()
Returns pointer to the embedded SVG selector widget.
typedef StandardButtons
QCheckBox * relativePathCheckbox()
QLineEdit * filePathLineEdit()
typedef WindowFlags