QGIS API Documentation 4.3.0-Master (149067ad0b9)
Loading...
Searching...
No Matches
qgsdatetimewithtimezonewidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdatetimewithtimezonewidget.h
3 --------------------------------------
4 Date : October 2026
5 Copyright : (C) 2026 Nyall Dawson
6 Email : nyall.dawson@gmail.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 QGSDATETIMEWITHTIMEZONEWIDGET_H
17#define QGSDATETIMEWITHTIMEZONEWIDGET_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include "qgsguiutils.h"
22#include "qgspanelwidget.h"
23
24#include <QAbstractItemModel>
25#include <QConcatenateTablesProxyModel>
26#include <QDialog>
27#include <QPointer>
28#include <QSortFilterProxyModel>
29#include <QWidget>
30
32class QListView;
33class QComboBox;
34class QToolButton;
35class StandardTimeZoneModel;
36class StandardTimeZoneProxyModel;
37class QDialogButtonBox;
38class QgsDateTimeEdit;
39
46class GUI_EXPORT QgsTimeZoneItemModel : public QAbstractItemModel
47{
48 Q_OBJECT
49
50 public:
52 enum class CustomRole : int
53 {
54 TimeZoneId = Qt::UserRole,
55 TimeZone,
56 UtcOffset,
57 };
58 Q_ENUM( CustomRole )
59
60
63 QgsTimeZoneItemModel( QObject *parent SIP_TRANSFER = nullptr );
64
65 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
66 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
67 QVariant data( const QModelIndex &index, int role ) const override;
68 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
69 QModelIndex parent( const QModelIndex &index ) const override;
70
74 QModelIndex indexFromTimeZone( const QTimeZone &timeZone ) const;
75
79 static QString displayStringForTimeZone( const QTimeZone &timeZone, QTimeZone::NameType nameType = QTimeZone::NameType::DefaultName );
80
81 private:
82 struct TimeZoneItem
83 {
84 QString id;
85 QString displayString;
86 QTimeZone timeZone;
87 int utcOffset = 0;
88 };
89 static std::vector< TimeZoneItem > sItems;
90
91 static QString offsetToString( int seconds );
92};
93
100class GUI_EXPORT QgsTimeZoneSortFilterModel : public QSortFilterProxyModel
101{
102 Q_OBJECT
103
104 public:
110 QgsTimeZoneSortFilterModel( QgsTimeZoneItemModel *source, QObject *parent SIP_TRANSFER = nullptr );
111
117 QString filterString() const { return mFilterString; }
118
122 QModelIndex indexFromTimeZone( const QTimeZone &timeZone ) const;
123
124 public slots:
125
132 void setFilterString( const QString &filter );
133
134 protected:
135 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
136 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
137
138 private:
139 QgsTimeZoneItemModel *mSourceModel = nullptr;
140 QString mFilterString;
141};
142
151class GUI_EXPORT QgsTimeZoneWidget : public QgsPanelWidget
152{
153 Q_OBJECT
154
155 public:
159 explicit QgsTimeZoneWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
160
168 QTimeZone timeZone() const;
169
170 public slots:
171
177 void setTimeZone( const QTimeZone &zone );
178
179 signals:
180
187 void timeZoneChanged( const QTimeZone &zone );
188
192 void timeZoneDoubleClicked( const QTimeZone &zone );
193
194 private slots:
195
196 void itemDoubleClicked( const QModelIndex &index );
197
198 private:
199 QgsTimeZoneItemModel *mModel = nullptr;
200 QgsTimeZoneSortFilterModel *mProxyModel = nullptr;
201
202 QgsFilterLineEdit *mFilterEdit = nullptr;
203 QListView *mListView = nullptr;
204};
205
206
215class GUI_EXPORT QgsTimeZoneDialog : public QDialog
216{
217 Q_OBJECT
218
219 public:
223 QgsTimeZoneDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
224
232 QTimeZone timeZone() const;
233
234 public slots:
235
241 void setTimeZone( const QTimeZone &zone );
242
243
244 private:
245 QgsTimeZoneWidget *mWidget = nullptr;
246 QDialogButtonBox *mButtonBox = nullptr;
247};
248
257class GUI_EXPORT QgsTimeZoneComboBox : public QWidget
258{
259 Q_OBJECT
260
261 public:
263 enum class StandardItem SIP_ENUM_BASETYPE( IntFlag )
264 {
265 Invalid = 1 << 0,
266 Current = 1 << 1,
267 System = 1 << 2,
268 };
269
273 Q_DECLARE_FLAGS( StandardItems, StandardItem )
274
275
278 explicit QgsTimeZoneComboBox( QWidget *parent SIP_TRANSFERTHIS = nullptr );
279
287 QTimeZone timeZone() const;
288
293 void setDialogTitle( const QString &title );
294
299 QString dialogTitle() const;
300
301 public slots:
302
308 void setTimeZone( const QTimeZone &zone );
309
310 signals:
311
318 void timeZoneChanged( const QTimeZone &zone );
319
320 private slots:
321
322 void selectTimeZone();
323
324 private:
325 QComboBox *mComboBox = nullptr;
326 QToolButton *mButton = nullptr;
327 StandardTimeZoneProxyModel *mTimeZoneModel = nullptr;
328 int mBlockSignals = 0;
329 QPointer< QgsTimeZoneWidget> mActivePanel;
330 int mIgnorePanelSignals = 0;
331 QString mDialogTitle;
332};
333
335
337
338class StandardTimeZoneModel : public QAbstractItemModel SIP_SKIP
339{
340 Q_OBJECT
341
342 public:
343 enum class CustomRole : int
344 {
345 TimeZone = Qt::UserRole,
346 };
347 StandardTimeZoneModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
348
349 QVariant data( const QModelIndex &index, int role ) const override;
350 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
351 int columnCount( const QModelIndex & = QModelIndex() ) const override;
352 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
353 QModelIndex parent( const QModelIndex &index ) const override;
354
355 QgsTimeZoneComboBox::StandardItem itemForIndex( const QModelIndex &index ) const;
356 QModelIndex indexForItem( QgsTimeZoneComboBox::StandardItem item ) const;
357 void setCurrentTimeZone( const QTimeZone &timeZone );
358
359 private:
360 QString mNotSetText;
361 QTimeZone mCurrentTimeZone;
362};
363
364class StandardTimeZoneProxyModel : public QSortFilterProxyModel SIP_SKIP
365{
366 Q_OBJECT
367
368 public:
369 StandardTimeZoneProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
370 void setDisplayedItems( QgsTimeZoneComboBox::StandardItems items );
371 void setCurrentTimeZone( const QTimeZone &timeZone );
372 QModelIndex indexForItem( QgsTimeZoneComboBox::StandardItem item ) const;
373
374 protected:
375 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
376
377 private:
378 StandardTimeZoneModel *mModel = nullptr;
380};
381
382
384
391class GUI_EXPORT QgsDateTimeWithTimeZoneWidget : public QWidget
392{
393 Q_OBJECT
394
395 public:
399 explicit QgsDateTimeWithTimeZoneWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
400
408
413
418 void setDialogTitle( const QString &title );
419
424 QString dialogTitle() const;
425
431 QDateTime dateTime() const;
432
433 public slots:
434
442 void setDateTime( const QDateTime &dateTime );
443
444 signals:
445
449 void dateTimeChanged( const QDateTime &dateTime );
450
451 private:
452 QgsDateTimeEdit *mDateTimeEdit = nullptr;
453 QgsTimeZoneComboBox *mTimeZoneCombo = nullptr;
454 int mBlockSignals = false;
455};
456
457#endif // QGSDATETIMEWITHTIMEZONEWIDGET_H
A QDateTimeEdit with the capability of setting/reading null date/times.
QgsDateTimeEdit * dateTimeEdit()
Returns the date time edit portion of the widget.
QgsDateTimeWithTimeZoneWidget(QWidget *parent=nullptr)
Constructor for QgsDateTimeWithTimeZoneWidget, with the specified parent widget.
void setDateTime(const QDateTime &dateTime)
Sets the date time to show in the widget.
QgsTimeZoneComboBox * timeZoneComboBox()
Returns the time zone combo box portion of the widget.
void dateTimeChanged(const QDateTime &dateTime)
Emitted whenever the date time shown in the widget is changed.
void setDialogTitle(const QString &title)
Sets the title for the time zone selector dialog window.
QDateTime dateTime() const
Returns the date time shown in the widget, with corresponding time zone set.
QString dialogTitle() const
Returns the title for the time zone selector dialog window.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
A combo box widget for selection of available time zones.
void setTimeZone(const QTimeZone &zone)
Sets the current time zone to select in the widget.
QString dialogTitle() const
Returns the title for the time zone selector dialog window.
void timeZoneChanged(const QTimeZone &zone)
Emitted when the selected time zone is changed.
QFlags< StandardItem > StandardItems
Standard time zone options.
QgsTimeZoneComboBox(QWidget *parent=nullptr)
Constructor for QgsTimeZoneComboBox, with the specified parent widget.
QTimeZone timeZone() const
Returns the selected time zone.
void setDialogTitle(const QString &title)
Sets the title for the time zone selector dialog window.
StandardItem
Standard time zone options.
QTimeZone timeZone() const
Returns the selected time zone.
QgsTimeZoneDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsTimeZoneDialog.
void setTimeZone(const QTimeZone &zone)
Sets the current time zone to select in the dialog.
A custom model for display of available time zones.
QgsTimeZoneItemModel(QObject *parent=nullptr)
Constructor for a QgsTimeZoneItemModel with the specified parent object.
A sort filter model for display of available time zones.
QgsTimeZoneSortFilterModel(QgsTimeZoneItemModel *source, QObject *parent=nullptr)
Constructor for a QgsTimeZoneSortFilterModel with the specified parent object and source model.
QString filterString() const
Returns the current filter string, if set.
A widget for selection of available time zones.
QgsTimeZoneWidget(QWidget *parent=nullptr)
Constructor for QgsTimeZoneWidget, with the specified parent widget.
void timeZoneDoubleClicked(const QTimeZone &zone)
Emitted when a time zone is double-clicked in the widget.
void setTimeZone(const QTimeZone &zone)
Sets the current time zone to select in the widget.
QTimeZone timeZone() const
Returns the selected time zone.
void timeZoneChanged(const QTimeZone &zone)
Emitted when the selected time zone is changed.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:277
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_TRANSFER
Definition qgis_sip.h:35
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTimeZoneComboBox::StandardItems)