1 /***************************************************************************
2     qgsdatetimesearchwidgetwrapper.h
3      -------------------------------
4     Date                 : 2016-05-23
5     Copyright            : (C) 2016 Nyall Dawson
6     Email                : nyall dot dawson at gmail dot com
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 QGSDATETIMESEARCHWIDGETWRAPPER_H
17 #define QGSDATETIMESEARCHWIDGETWRAPPER_H
18 
19 #include "qgssearchwidgetwrapper.h"
20 #include "qgis_sip.h"
21 
22 #include <QComboBox>
23 #include <QListWidget>
24 #include <QLineEdit>
25 #include "qgis_gui.h"
26 
27 class QgsDateTimeEditFactory;
28 class QgsDateTimeEdit;
29 
30 /**
31  * \ingroup gui
32  * \class QgsDateTimeSearchWidgetWrapper
33  * \brief Wraps a date/time edit widget for searching.
34  * \since QGIS 2.16
35  */
36 
37 class GUI_EXPORT QgsDateTimeSearchWidgetWrapper : public QgsSearchWidgetWrapper
38 {
39     Q_OBJECT
40 
41   public:
42 
43     /**
44      * Constructor for QgsDateTimeSearchWidgetWrapper.
45      * \param vl associated vector layer
46      * \param fieldIdx index of associated field
47      * \param parent parent widget
48      */
49     explicit QgsDateTimeSearchWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *parent SIP_TRANSFERTHIS = nullptr );
50 
51     /**
52      * Returns a variant representing the current state of the widget, respecting
53      * the editor widget's configured field format for date/time values.
54      */
55     QVariant value() const;
56 
57     bool applyDirectly() override;
58     QString expression() const override;
59     bool valid() const override;
60     QgsSearchWidgetWrapper::FilterFlags supportedFlags() const override;
61     QgsSearchWidgetWrapper::FilterFlags defaultFlags() const override;
62     QString createExpression( QgsSearchWidgetWrapper::FilterFlags flags ) const override;
63 
64   public slots:
65 
66     void clearWidget() override;
67     void setEnabled( bool enabled ) override;
68 
69   protected:
70     QWidget *createWidget( QWidget *parent ) override;
71     void initWidget( QWidget *editor ) override;
72 
73   protected slots:
74     void setExpression( const QString &exp ) override;
75 
76   private slots:
77     void dateTimeChanged( const QDateTime &date );
78 
79   private:
80     QgsDateTimeEdit *mDateTimeEdit = nullptr;
81     QgsVectorLayer *mLayer = nullptr;
82 
83     friend class QgsDateTimeEditFactory;
84 };
85 
86 #endif // QGSDATETIMESEARCHWIDGETWRAPPER_H
87