KProperty

datetimeedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4 Copyright (C) 2012 Friedrich W. H. Kossebau <kossebau@kde.org>
5 Copyright (C) 2015 Jarosław Staniek <staniek@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21*/
22
23#include "datetimeedit.h"
24#include "KPropertyWidgetsFactory.h"
25#include "KPropertyUtils.h"
26
27#include <QLocale>
28
29class Q_DECL_HIDDEN KPropertyDateTimeEditor::Private
30{
31public:
32 Private()
33 {
34 }
35};
36
37KPropertyDateTimeEditor::KPropertyDateTimeEditor(const KProperty* prop, QWidget* parent)
38 : QDateTimeEdit(parent), d(new Private)
39{
40 setFrame(false);
41 setCalendarPopup(true);
42
43 if (prop->hasOptions()) {
44 const QDateTime minDateTime = prop->option("min", minimumDateTime()).toDateTime();
45 const QDateTime maxDateTime = prop->option("max", maximumDateTime()).toDateTime();
46 if (minDateTime.isValid() && maxDateTime.isValid() && minDateTime <= maxDateTime) {
47 setDateTimeRange(minDateTime, maxDateTime);
48 }
49 const QString minValueText(prop->option("minValueText").toString());
50 if (!minValueText.isEmpty()) {
51 setSpecialValueText(minValueText);
52 }
53 }
54 connect(this, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(onDateTimeChanged()));
55}
56
57KPropertyDateTimeEditor::~KPropertyDateTimeEditor()
58{
59 delete d;
60}
61
62QVariant KPropertyDateTimeEditor::value() const
63{
64 return QVariant(dateTime());
65}
66
67void KPropertyDateTimeEditor::setValue(const QVariant& value)
68{
69 blockSignals(true);
70 setDateTime(value.toDateTime());
71 blockSignals(false);
72}
73
74void KPropertyDateTimeEditor::paintEvent(QPaintEvent* event)
75{
77 KPropertyWidgetsFactory::paintTopGridLine(this);
78}
79
80
81void KPropertyDateTimeEditor::onDateTimeChanged()
82{
83 emit commitData(this);
84}
85
86
87//! @todo Port to KLocale, be inspired by KexiDateTimeTableEdit (with Kexi*Formatter)
88KPropertyDateTimeDelegate::KPropertyDateTimeDelegate()
89{
90}
91
92QString KPropertyDateTimeDelegate::valueToString(const QVariant& value, const QLocale &locale) const
93{
94 const QString defaultDateTimeFormat = locale.dateTimeFormat(QLocale::ShortFormat);
95 return value.toDateTime().toString(defaultDateTimeFormat);
96}
97
98QWidget* KPropertyDateTimeDelegate::createEditor(int type, QWidget* parent,
99 const QStyleOptionViewItem& option, const QModelIndex& index) const
100{
101 Q_UNUSED(type);
102 Q_UNUSED(option);
103
104 KProperty *prop = KPropertyUtils::propertyForIndex(index);
105 if (!prop) {
106 return nullptr;
107 }
108 return new KPropertyDateTimeEditor(prop, parent);
109}
The base class representing a single property.
Definition KProperty.h:96
QVariant option(const char *name, const QVariant &defaultValue=QVariant()) const
Returns value of given option Option is set if returned value is not null. If there is no option for ...
bool hasOptions() const
Returns true if at least one option is specified for this property If there are no options defined tr...
bool isValid() const const
QString toString(QStringView format, QCalendar cal) const const
virtual bool event(QEvent *event) override
virtual void paintEvent(QPaintEvent *event) override
QString dateTimeFormat(FormatType format) const const
bool blockSignals(bool block)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QDateTime toDateTime() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.