QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
QgsDateTimeEdit Class Reference

A QDateTimeEdit with the capability of setting/reading null date/times. More...

#include <qgsdatetimeedit.h>

Inheritance diagram for QgsDateTimeEdit:

Signals

void valueChanged (const QDateTime &date)
 Signal emitted whenever the value changes.

Public Member Functions

 QgsDateTimeEdit (QWidget *parent=nullptr)
 Constructor for QgsDateTimeEdit.
bool allowNull () const
 If the widget allows setting null date/time.
void clear () override
 Set the current date as NULL.
QDate date () const
 Returns the date which can be a null date.
QDateTime dateTime () const
 Returns the date time which can be a null date/time.
bool event (QEvent *event) override
 Reimplemented to enable/disable the clear action depending on read-only status.
QString nullRepresentation () const
 Returns the widget's NULL representation, which defaults to QgsApplication::nullRepresentation().
void setAllowNull (bool allowNull)
 Determines if the widget allows setting null date/time.
void setDateTime (const QDateTime &dateTime)
 Set the date time in the widget and handles null date times.
void setEmpty ()
 Resets the widget to show no value (ie, an "unknown" state).
void setNullRepresentation (const QString &null)
 Sets the widget's null representation, which defaults to QgsApplication::nullRepresentation().
QTime time () const
 Returns the time which can be a null time.

Protected Member Functions

void displayNull (bool updateCalendar=false)
 write the null value representation to the line edit without changing the value
virtual void emitValueChanged (const QVariant &value)
 Emits the widget's correct value changed signal.
void focusInEvent (QFocusEvent *event) override
void focusOutEvent (QFocusEvent *event) override
bool isNull () const
 Returns true if the widget is currently set to a null value.
void mousePressEvent (QMouseEvent *event) override
void showEvent (QShowEvent *event) override
void wheelEvent (QWheelEvent *event) override

Protected Attributes

int mBlockChangedSignal = 0
 Block change signals if true.
bool mIsEmpty = false
 true if the widget is empty

Properties

bool allowNull

Friends

class TestQgsDateTimeEdit

Detailed Description

A QDateTimeEdit with the capability of setting/reading null date/times.

Warning
You should use the signal valueChanged of this subclass rather than QDateTimeEdit::dateTimeChanged. (If you consequently connect parent's dateTimeChanged signal and call dateTime() afterwards there is no guarantee that NULL values will be correctly handled).
See also
QgsDateEdit
QgsTimeEdit

Definition at line 37 of file qgsdatetimeedit.h.

Constructor & Destructor Documentation

◆ QgsDateTimeEdit()

QgsDateTimeEdit::QgsDateTimeEdit ( QWidget * parent = nullptr)
explicit

Constructor for QgsDateTimeEdit.

The current date and time is used by default. The widget is allowing null by default. If allow null is disabled, you should check allowNull before getting values from the widget.

Definition at line 30 of file qgsdatetimeedit.cpp.

Member Function Documentation

◆ allowNull()

bool QgsDateTimeEdit::allowNull ( ) const
inline

If the widget allows setting null date/time.

See also
setAllowNull

Definition at line 62 of file qgsdatetimeedit.h.

◆ clear()

void QgsDateTimeEdit::clear ( )
override

Set the current date as NULL.

Note
If the widget is not configured to accept NULL dates, this will have no effect.

Definition at line 75 of file qgsdatetimeedit.cpp.

◆ date()

QDate QgsDateTimeEdit::date ( ) const

Returns the date which can be a null date.

Since
QGIS 3.10

Definition at line 408 of file qgsdatetimeedit.cpp.

◆ dateTime()

QDateTime QgsDateTimeEdit::dateTime ( ) const

Returns the date time which can be a null date/time.

Note
Before QGIS 3.10, you mustn't call date() or time() because they can't return a NULL value.
Since QDateTimeEdit::dateTime() is not virtual, dateTime must be called for QgsDateTimeEdit.

Definition at line 384 of file qgsdatetimeedit.cpp.

◆ displayNull()

void QgsDateTimeEdit::displayNull ( bool updateCalendar = false)
protected

write the null value representation to the line edit without changing the value

Parameters
updateCalendarFlag if calendar is open and minimum date needs to be set

Definition at line 286 of file qgsdatetimeedit.cpp.

◆ emitValueChanged()

void QgsDateTimeEdit::emitValueChanged ( const QVariant & value)
protectedvirtual

Emits the widget's correct value changed signal.

Reimplemented in QgsDateEdit, and QgsTimeEdit.

Definition at line 300 of file qgsdatetimeedit.cpp.

◆ event()

bool QgsDateTimeEdit::event ( QEvent * event)
override

Reimplemented to enable/disable the clear action depending on read-only status.

Since
QGIS 3.34

Definition at line 104 of file qgsdatetimeedit.cpp.

◆ focusInEvent()

void QgsDateTimeEdit::focusInEvent ( QFocusEvent * event)
overrideprotected

Definition at line 207 of file qgsdatetimeedit.cpp.

◆ focusOutEvent()

void QgsDateTimeEdit::focusOutEvent ( QFocusEvent * event)
overrideprotected

Definition at line 188 of file qgsdatetimeedit.cpp.

◆ isNull()

bool QgsDateTimeEdit::isNull ( ) const
protected

Returns true if the widget is currently set to a null value.

Definition at line 305 of file qgsdatetimeedit.cpp.

◆ mousePressEvent()

void QgsDateTimeEdit::mousePressEvent ( QMouseEvent * event)
overrideprotected

Definition at line 130 of file qgsdatetimeedit.cpp.

◆ nullRepresentation()

QString QgsDateTimeEdit::nullRepresentation ( ) const

Returns the widget's NULL representation, which defaults to QgsApplication::nullRepresentation().

See also
setNullRepresentation()
Since
QGIS 3.14

Definition at line 272 of file qgsdatetimeedit.cpp.

◆ setAllowNull()

void QgsDateTimeEdit::setAllowNull ( bool allowNull)

Determines if the widget allows setting null date/time.

See also
allowNull

Definition at line 68 of file qgsdatetimeedit.cpp.

◆ setDateTime()

void QgsDateTimeEdit::setDateTime ( const QDateTime & dateTime)

Set the date time in the widget and handles null date times.

Note
Since QDateTimeEdit::setDateTime() is not virtual, setDateTime must be called for QgsDateTimeEdit.

Definition at line 352 of file qgsdatetimeedit.cpp.

◆ setEmpty()

void QgsDateTimeEdit::setEmpty ( )

Resets the widget to show no value (ie, an "unknown" state).

Definition at line 98 of file qgsdatetimeedit.cpp.

◆ setNullRepresentation()

void QgsDateTimeEdit::setNullRepresentation ( const QString & null)

Sets the widget's null representation, which defaults to QgsApplication::nullRepresentation().

See also
nullRepresentation()
Since
QGIS 3.14

Definition at line 277 of file qgsdatetimeedit.cpp.

◆ showEvent()

void QgsDateTimeEdit::showEvent ( QShowEvent * event)
overrideprotected

Definition at line 235 of file qgsdatetimeedit.cpp.

◆ time()

QTime QgsDateTimeEdit::time ( ) const

Returns the time which can be a null time.

Since
QGIS 3.10

Definition at line 396 of file qgsdatetimeedit.cpp.

◆ valueChanged

void QgsDateTimeEdit::valueChanged ( const QDateTime & date)
signal

Signal emitted whenever the value changes.

Parameters
dateThe new date/time value.

◆ wheelEvent()

void QgsDateTimeEdit::wheelEvent ( QWheelEvent * event)
overrideprotected

Definition at line 223 of file qgsdatetimeedit.cpp.

◆ TestQgsDateTimeEdit

friend class TestQgsDateTimeEdit
friend

Definition at line 214 of file qgsdatetimeedit.h.

Member Data Documentation

◆ mBlockChangedSignal

int QgsDateTimeEdit::mBlockChangedSignal = 0
protected

Block change signals if true.

Definition at line 155 of file qgsdatetimeedit.h.

◆ mIsEmpty

bool QgsDateTimeEdit::mIsEmpty = false
protected

true if the widget is empty

Definition at line 152 of file qgsdatetimeedit.h.

Property Documentation

◆ allowNull

bool QgsDateTimeEdit::allowNull
readwrite

Definition at line 40 of file qgsdatetimeedit.h.


The documentation for this class was generated from the following files: