3
* TOra - An Oracle Toolkit for DBA's and developers
4
* Copyright (C) 2003-2005 Quest Software, Inc
5
* Portions Copyright (C) 2005 Other Contributors
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; only version 2 of
10
* the License is valid for this program.
12
* This program 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
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* As a special exception, you have permission to link this program
22
* with the Oracle Client libraries and distribute executables, as long
23
* as you follow the requirements of the GNU GPL in regard to all of the
24
* software in the executable aside from Oracle client libraries.
26
* Specifically you are not permitted to link this program with the
27
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
28
* And you are not permitted to distribute binaries compiled against
29
* these libraries without written consent from Quest Software, Inc.
30
* Observe that this does not disallow linking to the Qt Free Edition.
32
* You may link this product with any GPL'd Qt library such as Qt/Free
34
* All trademarks belong to their respective owners.
42
#include "tomemoeditor.h"
43
#include "toparamget.h"
46
#include <qapplication.h>
47
#include <qcheckbox.h>
48
#include <qcombobox.h>
52
#include <qlineedit.h>
54
#include <qpushbutton.h>
56
#include <qscrollview.h>
57
#include <qsizepolicy.h>
59
#include "toparamget.moc"
61
std::map<QString, std::list<QString> > toParamGet::DefaultCache;
62
std::map<QString, std::list<QString> > toParamGet::Cache;
64
toParamGet::toParamGet(QWidget *parent, const char *name)
65
: QDialog(parent, name, true), toHelpContext(QString::fromLatin1("common.html#param"))
67
toHelp::connectDialog(this);
69
setCaption(tr("Define binding variables"));
71
QGridLayout *layout = new QGridLayout(this, 3, 2);
72
layout->setSpacing( 6 );
73
layout->setMargin( 11 );
75
View = new QScrollView(this);
76
View->enableClipper(true);
77
View->setGeometry(10, 10, 330, 480);
78
View->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
79
layout->addMultiCellWidget(View, 0, 2, 0, 0);
81
Container = new QGrid(4, View->viewport());
82
View->addChild(Container, 5, 5);
83
Container->setSpacing(10);
84
Container->setFixedWidth(View->width() - 30);
85
View->viewport()->setBackgroundColor(qApp->palette().active().background());
87
QPushButton *OkButton = new QPushButton(this, "OkButton");
88
OkButton->setText(tr("&Ok"));
89
OkButton->setDefault(true);
90
layout->addWidget(OkButton, 0, 1);
92
QPushButton *CancelButton = new QPushButton(this, "CancelButton");
93
CancelButton->setText(tr("Cancel"));
94
CancelButton->setDefault(false);
95
layout->addWidget(CancelButton, 1, 1);
97
QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
98
layout->addItem(spacer, 2, 1);
100
connect(OkButton, SIGNAL(clicked()), this, SLOT(accept()));
101
connect(CancelButton, SIGNAL(clicked()), this, SLOT(reject()));
104
toQList toParamGet::getParam(toConnection &conn, QWidget *parent, QString &str, bool interactive)
106
std::map<QString, bool> parameters;
107
std::list<QString> names;
108
toParamGet *widget = NULL;
127
QString def = QString::fromLatin1("<char[4000]>");
132
for (unsigned int i = 0;i < str.length() + 1;i++)
143
if(i < str.length() - 1)
149
if (state == normal && c == '-' && nc == '-')
151
else if (state == normal && c == '/' && nc == '*')
152
state = multiComment;
166
if (c == '*' && nc == '/')
179
// this is a type cast for postgres, not a parameter.
180
if(nc == ':' || pc == ':')
189
fname = QString::fromLatin1("f");
190
fname += QString::number(colon);
192
res += QString::fromLatin1(":");
194
res += def.mid(0, def.length() - 1);
195
c = def.at(def.length() - 1);
200
if (c.isLetterOrNumber() || c == '_')
205
if (fname.isEmpty() && !toIsMySQL(conn))
207
toStatusMessage(tr("Missing field name"));
208
throw tr("Missing field name");
213
state = specification;
234
if (state == normal && !fname.isEmpty())
237
fname.replace(QRegExp("_"), " ");
240
if (direction.isEmpty() || direction == "in" || direction == "inout")
242
if (!parameters[fname])
244
parameters[fname] = true;
246
widget = new toParamGet(parent);
247
new QLabel(fname, widget->Container);
248
QComboBox *edit = new QComboBox(widget->Container, QString::number(num));
249
edit->setEditable(true);
251
std::map<QString, std::list<QString> >::iterator fnd = Cache.find(fname);
252
if (fnd != Cache.end())
253
for (std::list<QString>::iterator i = (*fnd).second.begin();i != (*fnd).second.end();i++)
255
if (edit->count() == 0)
257
edit->insertItem(*i);
260
fnd = DefaultCache.find(fname);
261
if (fnd != DefaultCache.end())
262
for (std::list<QString>::iterator i = (*fnd).second.begin();i != (*fnd).second.end();i++)
264
if (edit->count() == 0)
266
edit->insertItem(*i);
269
QCheckBox *box = new QCheckBox(tr("NULL"), widget->Container);
270
connect(box, SIGNAL(toggled(bool)), edit, SLOT(setDisabled(bool)));
271
if (edit->count() > 0)
274
box->setChecked(true);
276
toParamGetButton *btn = new toParamGetButton(num, widget->Container);
277
btn->setText(tr("Edit"));
278
btn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
279
connect(btn, SIGNAL(clicked(int)), widget, SLOT(showMemo(int)));
280
connect(box, SIGNAL(toggled(bool)), btn, SLOT(setDisabled(bool)));
281
widget->Value.insert(widget->Value.end(), edit);
282
names.insert(names.end(), fname);
284
QDesktopWidget *paramDesktop = new QDesktopWidget;
285
edit->setMaximumWidth(paramDesktop->availableGeometry(edit).width()*2/3);
286
edit->setMinimumWidth(100);
287
edit->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
294
if (i < str.length())
301
(*widget->Value.begin())->setFocus();
302
if (!interactive || widget->exec())
304
std::list<QString>::iterator cn = names.begin();
305
for (std::list<QComboBox *>::iterator i = widget->Value.begin();i != widget->Value.end();i++)
307
QComboBox *current = *i;
311
if (current->isEnabled())
312
val = current->currentText();
316
if (cn != names.end())
318
std::list<QString> &lst = Cache[*cn];
319
for (std::list<QString>::iterator i = lst.begin();i != lst.end();i++)
325
lst.insert(lst.begin(), val);
327
std::map<QString, std::list<QString> >::iterator fnd = DefaultCache.find(*cn);
328
if (fnd != DefaultCache.find(*cn))
329
for (std::list<QString>::iterator i = (*fnd).second.begin();i != (*fnd).second.end();i++)
332
(*fnd).second.erase(i);
338
ret.insert(ret.end(), val);
345
toStatusMessage(tr("Aborted execution"), false, false);
346
throw tr("Aborted execution");
353
void toParamGet::setDefault(toConnection &, const QString &name, const QString &val)
355
std::map<QString, std::list<QString> >::iterator fnd = Cache.find(name);
356
if (fnd != Cache.end())
357
for (std::list<QString>::iterator i = (*fnd).second.begin();i != (*fnd).second.end();i++)
361
std::list<QString> &lst = DefaultCache[name];
362
for (std::list<QString>::iterator i = lst.begin();i != lst.end();i++)
368
lst.insert(lst.begin(), val);
371
void toParamGet::showMemo(int row)
373
QObject *obj = child(QString::number(row));
376
toMemoEditor *memo = new toMemoEditor(this,
377
((QComboBox *) obj)->currentText(),
383
((QComboBox *)obj)->setCurrentText(memo->text());
387
void toParamGet::resizeEvent(QResizeEvent *e)
389
QDialog::resizeEvent(e);
390
Container->setFixedWidth(View->width() - 30);