QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  QgsDateTimeEdit( const QVariant &var, QVariant::Type parserType, QWidget *parent );
137 #endif
138 
140  bool mIsEmpty = false;
141 
143  int mBlockChangedSignal = 0;
144 
149  void displayNull( bool updateCalendar = false );
150 
154  virtual void emitValueChanged( const QVariant &value );
155 
159  bool isNull() const;
160 
161  protected slots:
162 #ifndef SIP_RUN
163  void changed( const QVariant &dateTime );
166 #endif
167 
168 
169  private:
170  bool mCurrentPressEvent = false;
171 
172  QString mOriginalStyleSheet = QString();
173  QAction *mClearAction;
174  QString mNullRepresentation;
175 
177  bool mAllowNull = true;
178 
180  bool mIsNull = false;
181 
185  void displayCurrentDate();
186 
188  void resetBeforeChange( int delta );
189 
203  void setMinimumEditDateTime()
204  {
205  setDateTimeRange( QDateTime( QDate( 1, 1, 1 ), QTime( 0, 0, 0 ) ), maximumDateTime() );
206  }
207 
208  friend class TestQgsDateTimeEdit;
209 };
210 
211 
226 class GUI_EXPORT QgsTimeEdit : public QgsDateTimeEdit
227 {
228  Q_OBJECT
229 
230  public:
231 
238  explicit QgsTimeEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
239 
244  void setTime( const QTime &time );
245 
246  signals:
247 
251  void timeValueChanged( const QTime &time );
252 
253  protected:
254  void emitValueChanged( const QVariant &value ) override;
255 
256 };
257 
272 class GUI_EXPORT QgsDateEdit : public QgsDateTimeEdit
273 {
274  Q_OBJECT
275 
276  public:
277 
284  explicit QgsDateEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
285 
290  void setDate( const QDate &date );
291 
292  signals:
293 
297  void dateValueChanged( const QDate &date );
298 
299  protected:
300  void emitValueChanged( const QVariant &value ) override;
301 
302 };
303 
304 #endif // QGSDATETIMEEDIT_H
QgsDateTimeEdit
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
Definition: qgsdatetimeedit.h:37
QgsDateEdit::dateValueChanged
void dateValueChanged(const QDate &date)
Signal emitted whenever the date changes.
QgsDateTimeEdit::emitValueChanged
virtual void emitValueChanged(const QVariant &value)
Emits the widget's correct value changed signal.
Definition: qgsdatetimeedit.cpp:258
QgsDateEdit
The QgsDateEdit class is a QDateEdit widget with the capability of setting/reading null dates.
Definition: qgsdatetimeedit.h:273
qgis_sip.h
QgsDateTimeEdit::valueChanged
void valueChanged(const QDateTime &date)
Signal emitted whenever the value changes.
QgsTimeEdit::timeValueChanged
void timeValueChanged(const QTime &time)
Signal emitted whenever the time changes.
QgsTimeEdit
The QgsTimeEdit class is a QTimeEdit widget with the capability of setting/reading null date/times.
Definition: qgsdatetimeedit.h:227
QgsDateTimeEdit::allowNull
bool allowNull() const
If the widget allows setting null date/time.
Definition: qgsdatetimeedit.h:61
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53