21 #include <QDateTimeEdit> 24 #include <QTextCharFormat> 25 #include <QCalendarWidget> 29 , mQDateTimeEdit( nullptr )
30 , mQgsDateTimeEdit( nullptr )
46 mQgsDateTimeEdit = qgsEditor;
54 mQDateTimeEdit = qtEditor;
57 if ( !mQDateTimeEdit )
59 QgsDebugMsg(
"Date/time edit widget could not be initialized because provided widget is not a QDateTimeEdit." );
67 const bool calendar =
config(
"calendar_popup",
false ).toBool();
81 const bool allowNull =
config(
"allow_null",
true ).toBool();
82 if ( mQgsDateTimeEdit )
89 "For that the QGIS custom widget QgsDateTimeEdit needs to be used." ),
93 if ( mQgsDateTimeEdit )
105 return mQgsDateTimeEdit || mQDateTimeEdit;
110 if ( mQgsDateTimeEdit )
114 void QgsDateTimeEditWrapper::dateTimeChanged(
const QDateTime& dateTime )
116 switch (
field().type() )
118 case QVariant::DateTime:
128 const bool fieldIsoFormat =
config(
"field_iso_format" ,
false ).toBool();
130 if ( fieldIsoFormat )
144 if ( !mQDateTimeEdit )
148 if ( mQgsDateTimeEdit )
150 dateTime = mQgsDateTimeEdit->
dateTime();
154 dateTime = mQDateTimeEdit->
dateTime();
157 switch (
field().type() )
159 case QVariant::DateTime:
163 return dateTime.
date();
166 return dateTime.
time();
169 const bool fieldIsoFormat =
config(
"field_iso_format",
false ).toBool();
171 if ( fieldIsoFormat )
173 return dateTime.
toString( Qt::ISODate );
177 return dateTime.
toString( fieldFormat );
186 if ( !mQDateTimeEdit )
191 switch (
field().type() )
193 case QVariant::DateTime:
199 const bool fieldIsoFormat =
config(
"field_iso_format",
false ).toBool();
201 if ( fieldIsoFormat )
212 if ( mQgsDateTimeEdit )
224 if ( !mQDateTimeEdit )
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
QString toString(Qt::DateFormat format) const
#define QGSDATETIMEEDIT_DATEFORMAT
QDateTime toDateTime() const
QgsDateTimeEditWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent=nullptr)
QString tr(const char *sourceText, const char *disambiguation, int n)
QVariant value() const override
Will be used to access the widget's value.
void setValue(const QVariant &value) override
void setEnabled(bool enabled) override
void setBackground(const QBrush &brush)
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
void setDateTextFormat(const QDate &date, const QTextCharFormat &format)
QDateTime fromString(const QString &string, Qt::DateFormat format)
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
bool valid() const override
Return true if the widget has been properly initialized.
QDateTime currentDateTime()
static QgsMessageLog * instance()
virtual void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
void setEmpty()
Resets the widget to show no value (ie, an "unknown" state).
void setAllowNull(bool allowNull)
determines if the widget allows setting null date/time.
void setDateTime(const QDateTime &dateTime)
setDateTime set the date time in the widget and handles null date times.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
QDateTime dateTime() const
dateTime returns the date time which can eventually be a null date/time
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times...