QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsfilewidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfilewidget.h
3 
4  ---------------------
5  begin : 17.12.2015
6  copyright : (C) 2015 by Denis Rouzaud
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSFILEWIDGET_H
18 #define QGSFILEWIDGET_H
19 
20 class QLabel;
21 class QToolButton;
22 class QVariant;
23 
24 class QgsFilterLineEdit;
25 
26 #include <QWidget>
27 
31 class GUI_EXPORT QgsFileWidget : public QWidget
32 {
33  Q_OBJECT
34  Q_PROPERTY( bool fileWidgetButtonVisible READ fileWidgetButtonVisible WRITE setFileWidgetButtonVisible )
35  Q_PROPERTY( bool useLink READ useLink WRITE setUseLink )
36  Q_PROPERTY( bool fullUrl READ fullUrl WRITE setFullUrl )
37  Q_PROPERTY( QString dialogTitle READ dialogTitle WRITE setDialogTitle )
38  Q_PROPERTY( QString filter READ filter WRITE setFilter )
39  Q_PROPERTY( QString defaultRoot READ defaultRoot WRITE setDefaultRoot )
40  Q_PROPERTY( StorageMode storageMode READ storageMode WRITE setStorageMode )
41  Q_PROPERTY( RelativeStorage relativeStorage READ relativeStorage WRITE setRelativeStorage )
42 
43  public:
48  {
50  GetDirectory
51  };
52 
57  {
60  RelativeDefaultPath
61  };
62 
66  explicit QgsFileWidget( QWidget *parent = 0 );
67 
68  ~QgsFileWidget();
69 
71  QString filePath();
72 
74  void setFilePath( QString path );
75 
77  void setReadOnly( bool readOnly );
78 
80  QString dialogTitle() const;
85  void setDialogTitle( const QString& title );
86 
88  QString filter() const;
93  void setFilter( const QString &filter );
94 
96  bool fileWidgetButtonVisible() const;
98  void setFileWidgetButtonVisible( bool visible );
99 
101  bool useLink() const;
103  void setUseLink( bool useLink );
104 
106  bool fullUrl() const;
108  void setFullUrl( bool fullUrl );
109 
111  QString defaultRoot() const;
113  void setDefaultRoot( const QString& defaultRoot );
114 
116  QgsFileWidget::StorageMode storageMode() const;
118  void setStorageMode( QgsFileWidget::StorageMode storageMode );
119 
121  QgsFileWidget::RelativeStorage relativeStorage() const;
123  void setRelativeStorage( QgsFileWidget::RelativeStorage relativeStorage );
124 
125  signals:
127  void fileChanged( const QString& );
128 
129  private slots:
130  void openFileDialog();
131  void textEdited( const QString& path );
132 
133  private:
134  QString mFilePath;
135  bool mButtonVisible;
136  bool mUseLink;
137  bool mFullUrl;
138  QString mDialogTitle;
139  QString mFilter;
140  QString mDefaultRoot;
141  StorageMode mStorageMode;
142  RelativeStorage mRelativeStorage;
143 
144  QLabel* mLinkLabel;
145  QgsFilterLineEdit* mLineEdit;
146  QToolButton* mFileWidgetButton;
147 
149  QString toUrl( const QString& path ) const;
150 
152  QString relativePath( const QString& filePath, bool removeRelative ) const;
153 
154  friend class TestQgsFileWidget;
155 };
156 
157 #endif // QGSFILEWIDGET_H
The QgsFileWidget class creates a widget for selecting a file or a folder.
Definition: qgsfilewidget.h:31
QLineEdit subclass with built in support for clearing the widget&#39;s value and handling custom null val...
StorageMode
The StorageMode enum determines if the file picker should pick files or directories.
Definition: qgsfilewidget.h:47
RelativeStorage
The RelativeStorage enum determines if path is absolute, relative to the current project path or rela...
Definition: qgsfilewidget.h:56