QGIS API Documentation  3.13.0-Master (740be229cb)
qgsfilecontentsourcelineedit.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfilecontentsourcelineedit.h
3  ---------------------
4  begin : July 2018
5  copyright : (C) 2018 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSFILECONTENTSOURCELINEEDIT_H
17 #define QGSFILECONTENTSOURCELINEEDIT_H
18 
19 #include "qgis_gui.h"
20 #include "qgis_sip.h"
21 #include <QWidget>
22 #include <QString>
23 
24 class QgsFilterLineEdit;
25 class QToolButton;
26 class QgsMessageBar;
27 
39 #ifndef SIP_RUN
40 class GUI_EXPORT QgsAbstractFileContentSourceLineEdit : public QWidget
41 {
42 #else
43 class GUI_EXPORT QgsAbstractFileContentSourceLineEdit : public QWidget SIP_ABSTRACT
44 {
45 #endif
46  Q_OBJECT
47  Q_PROPERTY( QString source READ source WRITE setSource NOTIFY sourceChanged )
48 
49  public:
50 
54  QgsAbstractFileContentSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
55 
61  void setMessageBar( QgsMessageBar *bar );
62 
67  QgsMessageBar *messageBar() const;
68 
74  QString source() const;
75 
80  void setLastPathSettingsKey( const QString &key );
81 
82  public slots:
83 
89  void setSource( const QString &source );
90 
91  signals:
92 
96  void sourceChanged( const QString &source );
97 
98  private:
99 
100 #ifndef SIP_RUN
101 
106  virtual QString fileFilter() const = 0;
107 
111  virtual QString selectFileTitle() const = 0;
112 
116  virtual QString fileFromUrlTitle() const = 0;
117 
121  virtual QString fileFromUrlText() const = 0;
122 
126  virtual QString embedFileTitle() const = 0;
127 
131  virtual QString extractFileTitle() const = 0;
132 
136  virtual QString defaultSettingsKey() const = 0;
137 
139 #endif
140 
141  private slots:
142  void selectFile();
143  void selectUrl();
144  void embedFile();
145  void extractFile();
146  void mFileLineEdit_textEdited( const QString &text );
147 
148  private:
149 
150  enum Mode
151  {
152  ModeFile,
153  ModeBase64,
154  };
155 
156  Mode mMode = ModeFile;
157 
158  QgsFilterLineEdit *mFileLineEdit = nullptr;
159  QToolButton *mFileToolButton = nullptr;
160  QString mLastPathKey;
161  QString mBase64;
162  QgsMessageBar *mMessageBar = nullptr;
163 
164  QString defaultPath() const;
165  QString settingsKey() const;
166 
167 };
168 
180 class GUI_EXPORT QgsSvgSourceLineEdit : public QgsAbstractFileContentSourceLineEdit
181 {
182  Q_OBJECT
183  public:
184 
188  QgsSvgSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr )
189  : QgsAbstractFileContentSourceLineEdit( parent )
190  {}
191 
192  private:
193 
194 #ifndef SIP_RUN
195  QString fileFilter() const override;
197  QString selectFileTitle() const override;
198  QString fileFromUrlTitle() const override;
199  QString fileFromUrlText() const override;
200  QString embedFileTitle() const override;
201  QString extractFileTitle() const override;
202  QString defaultSettingsKey() const override;
204 #endif
205 };
206 
207 
219 class GUI_EXPORT QgsImageSourceLineEdit : public QgsAbstractFileContentSourceLineEdit
220 {
221  Q_OBJECT
222  public:
223 
227  QgsImageSourceLineEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr )
228  : QgsAbstractFileContentSourceLineEdit( parent )
229  {}
230 
231  private:
232 #ifndef SIP_RUN
233  QString fileFilter() const override;
235  QString selectFileTitle() const override;
236  QString fileFromUrlTitle() const override;
237  QString fileFromUrlText() const override;
238  QString embedFileTitle() const override;
239  QString extractFileTitle() const override;
240  QString defaultSettingsKey() const override;
242 #endif
243 };
244 
245 #endif // QGSFILECONTENTSOURCELINEEDIT_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsImageSourceLineEdit(QWidget *parent=nullptr)
Constructor for QgsImageSourceLineEdit, with the specified parent widget.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
QgsSvgSourceLineEdit(QWidget *parent=nullptr)
Constructor for QgsSvgSourceLineEdit, with the specified parent widget.
A line edit widget with toolbutton for setting a raster image path.
Abstract base class for a widgets which allows users to select content from a file, embedding a file, etc.
#define SIP_ABSTRACT
Definition: qgis_sip.h:194
A line edit widget with toolbutton for setting an SVG image path.
QLineEdit subclass with built in support for clearing the widget&#39;s value and handling custom null val...