1
/* This file is part of the KDE project
2
Copyright (C) 2006-2015 Jarosław Staniek <staniek@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include "kexiqueryparameters.h"
21
#include <kexi_global.h>
22
#include "utils/kexidatetimeformatter.h"
24
#include <KDbQuerySchemaParameter>
28
#include <KLocalizedString>
31
#include <QInputDialog>
34
QList<QVariant> KexiQueryParameters::getParameters(QWidget *parent,
35
const KDbDriver &driver, KDbQuerySchema* querySchema, bool *ok)
38
Q_ASSERT(querySchema);
41
const QList<KDbQuerySchemaParameter> params(querySchema->parameters());
42
QList<QVariant> values;
43
const QString caption(xi18nc("@title:window Enter Query Parameter Value", "Enter Parameter Value"));
44
foreach(const KDbQuerySchemaParameter ¶meter, params) {
45
switch (parameter.type) {
47
case KDbField::ShortInteger:
48
case KDbField::Integer:
49
case KDbField::BigInteger: {
50
//! @todo problem for ranges in case of BigInteger - will disappear when we remove use of QInputDialog
51
qlonglong minValue, maxValue;
52
//! @todo add support for unsigned parameter here
53
KDb::getLimitsForFieldType(parameter.type, &minValue, &maxValue);
54
const int result = QInputDialog::getInt(parent, caption, parameter.message,
55
0, minValue, maxValue, 1/*step*/, ok);
57
return QList<QVariant>(); //cancelled
58
values.append(result);
61
case KDbField::Boolean: {
63
list << xi18nc("Boolean True - Yes", "Yes") << xi18nc("Boolean False - No", "No");
64
const QString result = QInputDialog::getItem(parent, caption, parameter.message,
65
list, 0/*current*/, false /* !editable*/,
67
if (!*ok || result.isEmpty())
68
return QList<QVariant>(); //cancelled
69
values.append(result == list.first());
72
case KDbField::Date: {
73
//! @todo KEXI3 re-add the KexiDateFormatter's inputMask for QInputDialog
75
const QString result = QInputDialog::getText(parent, caption, parameter.message,
76
QLineEdit::Normal, QString(), ok);
77
//! @todo KEXI3 add time validator
78
// 0/*validator*/, df.inputMask());
80
return QList<QVariant>(); //cancelled
81
values.append(df.fromString(result));
84
case KDbField::DateTime: {
85
//! @todo KEXI3 re-add the KexiDateTimeFormatter's inputMask for QInputDialog
88
const QString result = QInputDialog::getText(parent, caption, parameter.message,
89
QLineEdit::Normal, QString(), ok);
90
//! @todo KEXI3 add date time validator
91
// 0/*validator*/, KexiDateTimeFormatter::inputMask(df, tf));
93
return QList<QVariant>(); //cancelled
94
values.append(KexiDateTimeFormatter::fromString(df, tf, result));
97
case KDbField::Time: {
98
//! @todo KEXI3 re-add the KexiTimeFormatter's inputMask for QInputDialog
100
const QString result = QInputDialog::getText(parent, caption, parameter.message,
101
QLineEdit::Normal, QString(), ok);
102
//! @todo add validator
103
// 0/*validator*/, tf.inputMask());
105
return QList<QVariant>(); //cancelled
106
values.append(tf.fromString(result));
109
case KDbField::Float:
110
case KDbField::Double: {
111
// QInputDialog::getDouble() does not work well, use getText and double validator
112
//! @todo KEXI3 re-add double validator
113
// QDoubleValidator validator(0);
114
const QString textResult
115
= QInputDialog::getText(parent, caption, parameter.message, QLineEdit::Normal,
117
if (!*ok || textResult.isEmpty())
118
return QList<QVariant>(); //cancelled
119
//! @todo this value will be still rounded: consider storing them as a decimal type
120
//! (e.g. using a special qint64+decimalplace class)
121
const double result = textResult.toDouble(ok); //this is also good for float (to avoid rounding)
123
return QList<QVariant>();
124
values.append(result);
128
case KDbField::LongText: {
129
const QString result = QInputDialog::getText(parent, caption, parameter.message,
130
QLineEdit::Normal, QString(), ok);
132
return QList<QVariant>(); //cancelled
133
values.append(result);
136
case KDbField::BLOB: {
137
//! @todo BLOB input unsupported
138
values.append(QByteArray());
142
qWarning() << "unsupported type " << KDbField::typeName(parameter.type)
143
<< "for parameter \"" << parameter.message << "\" - aborting query execution!";
144
return QList<QVariant>();