QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
134 #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
140 #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
167  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
QgsDateTimeEdit
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
Definition: qgsdatetimeedit.h:36
QgsDateTimeEdit::emitValueChanged
virtual void emitValueChanged(const QVariant &value)
Emits the widget's correct value changed signal.
Definition: qgsdatetimeedit.cpp:273
QgsDateEdit
The QgsDateEdit class is a QDateEdit widget with the capability of setting/reading null dates.
Definition: qgsdatetimeedit.h:276
qgis_sip.h
QgsTimeEdit
The QgsTimeEdit class is a QTimeEdit widget with the capability of setting/reading null date/times.
Definition: qgsdatetimeedit.h:230
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53