QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
32 class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
33 {
34  Q_OBJECT
35  Q_PROPERTY( bool allowNull READ allowNull WRITE setAllowNull )
36 
37  public:
38 
45  explicit QgsDateTimeEdit( QWidget *parent SIP_TRANSFERTHIS = nullptr );
46 
51  void setAllowNull( bool allowNull );
52 
57  bool allowNull() const {return mAllowNull;}
58 
63  void setDateTime( const QDateTime &dateTime );
64 
70  QDateTime dateTime() const;
71 
76  QTime time() const;
77 
82  QDate date() const;
83 
88  void clear() override;
89 
94  void setEmpty();
95 
96  signals:
97 
102  void valueChanged( const QDateTime &date );
103 
104  protected:
105  void mousePressEvent( QMouseEvent *event ) override;
106  void focusOutEvent( QFocusEvent *event ) override;
107  void focusInEvent( QFocusEvent *event ) override;
108  void wheelEvent( QWheelEvent *event ) override;
109  void showEvent( QShowEvent *event ) override;
110 
111  private slots:
112  void changed( const QDateTime &dateTime );
113 
114  private:
115  bool mAllowNull = true;
116  bool mIsNull = false;
117  bool mIsEmpty = false;
118  bool mCurrentPressEvent = false;
119 
120  QString mOriginalStyleSheet = QString();
121  QAction *mClearAction;
122 
127  void displayNull( bool updateCalendar = false );
128 
132  void displayCurrentDate();
133 
135  void resetBeforeChange( int delta );
136 
148  void setMinimumEditDateTime()
149  {
150  setMinimumDateTime( QDateTime::fromString( QStringLiteral( "0100-01-01" ), Qt::ISODate ) );
151  }
152 
153  friend class TestQgsDateTimeEdit;
154 };
155 
156 #endif // QGSDATETIMEEDIT_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
bool allowNull() const
If the widget allows setting null date/time.
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times...