QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsdatetimeedit.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatetimeedit.h
3  --------------------------------------
4  Date : 08.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
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 QGSDATETIMEEDIT_H
17 #define QGSDATETIMEEDIT_H
18 
19 #include <QDateTimeEdit>
20 #include "qgis_sip.h"
21 #include "qgis_gui.h"
22 
36 class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
37 {
38  Q_OBJECT
39  Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull )
40 
41  public:
42 
49  explicit QgsDateTimeEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
50 
55  void setAllowNull( bool allowNull );
56 
61  bool allowNull() const {return mAllowNull;}
62 
67  void setDateTime( const QDateTime &dateTime );
68 
74  QDateTime dateTime() const;
75 
80  QTime time() const;
81 
86  QDate date() const;
87 
92  void clear() override;
93 
98  void setEmpty();
99 
107  QString nullRepresentation() const;
108 
116  void setNullRepresentation( const QString &null );
117 
118  signals:
119 
124  void valueChanged( const QDateTime &date );
125 
126  protected:
127  void mousePressEvent( QMouseEvent *event ) override;
128  void focusOutEvent( QFocusEvent *event ) override;
129  void focusInEvent( QFocusEvent *event ) override;
130  void wheelEvent( QWheelEvent *event ) override;
131  void showEvent( QShowEvent *event ) override;
132 
133 #ifndef SIP_RUN
135 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
136  QgsDateTimeEdit( const QVariant &var, QVariant::Type parserType, QWidget *parent );
137 #else
138  QgsDateTimeEdit( const QVariant &var, QMetaType::Type parserType, QWidget *parent );
139 #endif
141 #endif
142 
144  bool mIsEmpty = false;
145 
147  int mBlockChangedSignal = 0;
148 
153  void displayNull( bool updateCalendar = false );
154 
158  virtual void emitValueChanged( const QVariant &value );
159 
163  bool isNull() const;
164 
165  protected slots:
166 #ifndef SIP_RUN
168  void changed( const QVariant &dateTime );
170 #endif
171 
172 
173  private:
174  bool mCurrentPressEvent = false;
175 
176  QString mOriginalStyleSheet = QString();
177  QAction *mClearAction;
178  QString mNullRepresentation;
179 
181  bool mAllowNull = true;
182 
184  bool mIsNull = false;
185 
189  void displayCurrentDate();
190 
192  void resetBeforeChange( int delta );
193 
207  void setMinimumEditDateTime()
208  {
209  setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), maximumDateTime() );
210  }
211 
212  friend class TestQgsDateTimeEdit;
213 };
214 
215 
230 class GUI_EXPORT QgsTimeEdit : public QgsDateTimeEdit
231 {
232  Q_OBJECT
233 
234  public:
235 
242  explicit QgsTimeEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
243 
248  void setTime( const QTime &time );
249 
250  signals:
251 
255  void timeValueChanged( const QTime &time );
256 
257  protected:
258  void emitValueChanged( const QVariant &value ) override;
259 
260 };
261 
276 class GUI_EXPORT QgsDateEdit : public QgsDateTimeEdit
277 {
278  Q_OBJECT
279 
280  public:
281 
288  explicit QgsDateEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
289 
294  void setDate( const QDate &date );
295 
296  signals:
297 
301  void dateValueChanged( const QDate &date );
302 
303  protected:
304  void emitValueChanged( const QVariant &value ) override;
305 
306 };
307 
308 #endif // QGSDATETIMEEDIT_H
The QgsDateEdit class is a QDateEdit widget with the capability of setting/reading null dates.
void dateValueChanged(const QDate &date)
Signal emitted whenever the date changes.
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
bool allowNull() const
If the widget allows setting null date/time.
void valueChanged(const QDateTime &date)
Signal emitted whenever the value changes.
The QgsTimeEdit class is a QTimeEdit widget with the capability of setting/reading null date/times.
void timeValueChanged(const QTime &time)
Signal emitted whenever the time changes.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53