2
/* BEGIN_COMMON_COPYRIGHT_HEADER
4
* TOra - An Oracle Toolkit for DBA's and developers
6
* Shared/mixed copyright is held throughout files in this product
8
* Portions Copyright (C) 2000-2001 Underscore AB
9
* Portions Copyright (C) 2003-2005 Quest Software, Inc.
10
* Portions Copyright (C) 2004-2008 Numerous Other Contributors
12
* This program is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; only version 2 of
15
* the License is valid for this program.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
* As a special exception, you have permission to link this program
27
* with the Oracle Client libraries and distribute executables, as long
28
* as you follow the requirements of the GNU GPL in regard to all of the
29
* software in the executable aside from Oracle client libraries.
31
* Specifically you are not permitted to link this program with the
32
* Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
33
* And you are not permitted to distribute binaries compiled against
36
* You may link this product with any GPL'd Qt library.
38
* All trademarks belong to their respective owners.
40
* END_COMMON_COPYRIGHT_HEADER */
43
#include "toresultdata.h"
46
#include "toconfiguration.h"
47
#include "toresultdatasingle.h"
49
#include "ui_toresultcontentfilterui.h"
53
#include <QVBoxLayout>
54
#include <QMessageBox>
55
#include <QCloseEvent>
57
#include "icons/refresh.xpm"
58
#include "icons/addrecord.xpm"
59
#include "icons/canceledit.xpm"
60
#include "icons/duplicaterecord.xpm"
61
#include "icons/filter.xpm"
62
#include "icons/forward.xpm"
63
#include "icons/next.xpm"
64
#include "icons/nofilter.xpm"
65
#include "icons/previous.xpm"
66
#include "icons/rewind.xpm"
67
#include "icons/filesave.xpm"
68
#include "icons/single.xpm"
69
#include "icons/trash.xpm"
72
toResultData::toResultData(QWidget *parent,
83
QVBoxLayout *vbox = new QVBoxLayout;
84
vbox->setContentsMargins(0, 0, 0, 0);
87
QToolBar *toolbar = toAllocBar(this, tr("Content editor"));
88
vbox->addWidget(toolbar);
90
Edit = new toResultTableViewEdit(false, false, this);
91
vbox->addWidget(Edit);
93
Form = new toResultDataSingle(this);
94
vbox->addWidget(Form);
99
const toConnection::exception &,
104
singleRecordForm(false);
106
filterAct = toolbar->addAction(
107
QIcon(QPixmap(const_cast<const char**>(filter_xpm))),
108
tr("Define filter for editor"));
109
filterAct->setCheckable(true);
110
connect(filterAct, SIGNAL(triggered(bool)), this, SLOT(changeFilter(bool)));
112
removeAct = toolbar->addAction(
113
QIcon(QPixmap(const_cast<const char**>(nofilter_xpm))),
114
tr("Remove filters"));
115
connect(removeAct, SIGNAL(triggered(bool)), this, SLOT(removeFilter(bool)));
117
toolbar->addSeparator();
119
saveAct = toolbar->addAction(
120
QIcon(QPixmap(const_cast<const char**>(filesave_xpm))),
122
connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
123
connect(Edit, SIGNAL(changed(bool)), saveAct, SLOT(setEnabled(bool)));
125
addAct = toolbar->addAction(
126
QIcon(QPixmap(const_cast<const char**>(addrecord_xpm))),
127
tr("Add a new record"));
128
connect(addAct, SIGNAL(triggered()), this, SLOT(addRecord()));
130
duplicateAct = toolbar->addAction(
131
QIcon(QPixmap(const_cast<const char**>(duplicaterecord_xpm))),
132
tr("Duplicate an existing record"));
133
connect(duplicateAct, SIGNAL(triggered()), Edit, SLOT(duplicateRecord()));
135
deleteAct = toolbar->addAction(
136
QIcon(QPixmap(const_cast<const char**>(trash_xpm))),
137
tr("Delete current record from table"));
138
connect(deleteAct, SIGNAL(triggered()), Edit, SLOT(deleteRecord()));
140
toolbar->addSeparator();
142
refreshAct = toolbar->addAction(
143
QIcon(QPixmap(const_cast<const char**>(refresh_xpm))),
145
connect(refreshAct, SIGNAL(triggered()), this, SLOT(refreshWarn()));
147
toolbar->addSeparator();
149
firstAct = toolbar->addAction(
150
QIcon(QPixmap(const_cast<const char**>(rewind_xpm))),
151
tr("Go to first row"));
153
previousAct = toolbar->addAction(
154
QIcon(QPixmap(const_cast<const char**>(previous_xpm))),
155
tr("Go to previous row"));
157
nextAct = toolbar->addAction(
158
QIcon(QPixmap(const_cast<const char**>(next_xpm))),
159
tr("Go to next row"));
161
lastAct = toolbar->addAction(
162
QIcon(QPixmap(const_cast<const char**>(forward_xpm))),
163
tr("Go to last row"));
165
toolbar->addSeparator();
167
singleAct = toolbar->addAction(
168
QIcon(QPixmap(const_cast<const char**>(single_xpm))),
169
tr("Toggle between table or single record editing"));
170
singleAct->setCheckable(true);
171
connect(singleAct, SIGNAL(toggled(bool)), this, SLOT(singleRecordForm(bool)));
174
SIGNAL(actionTriggered(QAction *)),
176
SLOT(navigate(QAction *)));
182
void toResultData::query(const QString &, const toQList ¶ms)
189
if (params.size() == 2)
191
toQList::const_iterator par = params.begin();
197
/* Always check, if either is empty, query will fail */
198
if (Owner.isEmpty() || Table.isEmpty())
200
/* Need to clear columns here */
204
FilterName = filterName();
205
bool filter = AllFilter || Criteria.contains(FilterName);
206
filterAct->setChecked(filter);
208
toConnection &conn = connection();
210
SQL = "SELECT * FROM %1.%2";
211
SQL = SQL.arg(conn.quote(Owner)).arg(conn.quote(Table));
214
if (filter && !Criteria[FilterName].isEmpty())
217
SQL += Criteria[FilterName];
222
if (filter && !Order[FilterName].isEmpty())
225
SQL += Order[FilterName];
228
Edit->query(SQL, params);
232
void toResultData::exportData(std::map<QString, QString> &data,
233
const QString &prefix)
239
void toResultData::importData(std::map<QString, QString> &data,
240
const QString &prefix)
246
void toResultData::closeEvent(QCloseEvent *event)
255
void toResultData::navigate(QAction *action)
258
if (!Edit->selectionModel())
261
QModelIndex current = Edit->selectionModel()->currentIndex();
262
int row = current.row();
263
int col = current.column();
266
col = 1; // can't select hidden first column
268
if (action == firstAct)
270
else if (action == previousAct)
272
else if (action == nextAct)
274
else if (action == lastAct)
275
row = Edit->model()->rowCount() - 1;
277
return; // not a nav action
281
if (row >= Edit->model()->rowCount())
282
row = Edit->model()->rowCount() - 1;
284
QModelIndex left = Edit->model()->createIndex(row, col);
285
Edit->selectionModel()->select(QItemSelection(left, left),
286
QItemSelectionModel::ClearAndSelect);
287
Edit->setCurrentIndex(left);
289
// will update form if shown
290
singleRecordForm(singleAct->isChecked());
294
QString toResultData::filterName()
310
void toResultData::removeFilter(bool)
314
switch (TOMessageBox::information(
317
tr("Remove the filter for this table only or for all tables?"),
318
tr("&All"), tr("&This"), tr("Cancel"), 0))
323
// Intentionally no break
325
Criteria.remove(FilterName);
326
Order.remove(FilterName);
327
filterAct->setChecked(false);
336
Criteria.remove(nam);
339
filterAct->setChecked(false);
347
void toResultData::changeFilter(bool checked)
349
QDialog dialog(this);
350
Ui::toResultContentFilterUI filter;
351
filter.setupUi(&dialog);
353
FilterName = filterName();
355
filter.AllTables->setChecked(AllFilter);
356
filter.Order->setText(Order[FilterName]);
357
filter.Criteria->setText(Criteria[FilterName]);
359
filter.Columns->changeParams(Owner, Table);
363
AllFilter = filter.AllTables->isChecked();
365
FilterName = filterName();
366
Criteria[FilterName] = filter.Criteria->text();
367
Order[FilterName] = filter.Order->text();
373
if (Criteria[FilterName].isEmpty() && Order[FilterName].isEmpty())
374
filterAct->setChecked(false);
376
filterAct->setChecked(true);
380
bool toResultData::maybeSave(void)
382
if (!Edit->changed())
387
// grab focus so user can see file and decide to save
388
setFocus(Qt::OtherFocusReason);
390
int ret = TOMessageBox::information(
393
tr("Save changes to %1.%2?").arg(Owner).arg(Table),
395
QMessageBox::Discard |
396
QMessageBox::Cancel);
398
if (ret == QMessageBox::Save)
400
if (Edit->commitChanges())
404
else if (ret == QMessageBox::Discard)
405
return Discard = true;
411
void toResultData::singleRecordForm(bool display)
415
if (!Edit->selectionModel()->currentIndex().isValid())
417
QModelIndex left = Edit->model()->createIndex(0, 0);
418
Edit->selectionModel()->select(QItemSelection(left, left),
419
QItemSelectionModel::ClearAndSelect);
420
Edit->setCurrentIndex(left);
422
Form->changeRow(Edit->selectionModel()->currentIndex().row());
425
if(Form->currentRow() >= 0) {
426
// set selection to same as the form's
427
QModelIndex left = Edit->model()->createIndex(Form->currentRow(), 1);
428
Edit->selectionModel()->select(QItemSelection(left, left),
429
QItemSelectionModel::ClearAndSelect);
430
Edit->setCurrentIndex(left);
434
Form->setVisible(display);
435
Edit->setVisible(!display);
439
void toResultData::updateForm()
441
// update single edit form
444
Form->changeSource(Edit->model(),
445
Edit->selectionModel()->currentIndex().row());
450
void toResultData::save()
452
if (Edit->commitChanges())
457
void toResultData::addRecord()
460
// don't navigate here. done by Edit.
461
// navigate(lastAct);
465
void toResultData::refreshWarn()
469
switch (TOMessageBox(
470
QMessageBox::Warning,
472
tr("Refreshing from the database will lose current changes."),
473
QMessageBox::Ok | QMessageBox::Cancel,
476
case QMessageBox::Ok:
478
case QMessageBox::Cancel: