~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/toresultcontent.h

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****
 
2
*
 
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
 
6
 
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.
 
11
 
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.
 
16
 
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.
 
20
*
 
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.
 
25
*
 
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.
 
31
*
 
32
*      You may link this product with any GPL'd Qt library such as Qt/Free
 
33
*
 
34
* All trademarks belong to their respective owners.
 
35
*
 
36
*****/
 
37
 
 
38
#ifndef TORESULTCONTENT_H
 
39
#define TORESULTCONTENT_H
 
40
 
 
41
#include "config.h"
 
42
#include "tobackground.h"
 
43
#include "toconnection.h"
 
44
#include "toeditwidget.h"
 
45
#include "tomemoeditor.h"
 
46
#include "toresult.h"
 
47
 
 
48
#include <list>
 
49
#include <algorithm>
 
50
 
 
51
#include <qtable.h>
 
52
#include <qvbox.h>
 
53
 
 
54
class QChecBox;
 
55
class QCheckBox;
 
56
class QGrid;
 
57
class QLineEdit;
 
58
class toNoBlockQuery;
 
59
class toResultContent;
 
60
class toSearchReplace;
 
61
 
 
62
/** Implement memo editor in result content editor. Only for internal use.
 
63
 * @internal
 
64
 */
 
65
 
 
66
class toResultContentMemo : public toMemoEditor
 
67
{
 
68
    Q_OBJECT
 
69
 
 
70
    toResultContentEditor *contentEditor();
 
71
public:
 
72
    toResultContentMemo(QWidget *parent, const QString &data, int row, int col,
 
73
                        bool sql = false);
 
74
public slots:
 
75
    virtual void firstColumn();
 
76
    virtual void nextColumn();
 
77
    virtual void previousColumn();
 
78
    virtual void lastColumn();
 
79
 
 
80
    virtual void changePosition(int row, int cols);
 
81
};
 
82
 
 
83
/** This widget is used for single record view in the content editor. Only for internal use.
 
84
 * @internal
 
85
 */
 
86
 
 
87
class toResultContentSingle : public QScrollView
 
88
{
 
89
    Q_OBJECT
 
90
 
 
91
    int Row;
 
92
    QGrid *Container;
 
93
    std::list<QCheckBox *> Null;
 
94
    std::list<QLineEdit *> Value;
 
95
public:
 
96
    toResultContentSingle(QWidget *parent);
 
97
 
 
98
    void changeSource(QTable *table);
 
99
    void changeRow(QTable *table, int row);
 
100
    void saveRow(QTable *table, int row);
 
101
private slots:
 
102
    virtual void showMemo(int row);
 
103
};
 
104
 
 
105
/** This widget allows the user to browse the contents of a table and also edit
 
106
 * the content. The table is specified by the first and second parameter in the query.
 
107
 * The sql is not used in the query. Only for internal use.
 
108
 */
 
109
 
 
110
class toResultContentEditor : public QTable, public toEditWidget
 
111
{
 
112
    Q_OBJECT
 
113
 
 
114
    /** Single record form.
 
115
     */
 
116
    toResultContentSingle *SingleEdit;
 
117
    /** Owner of table.
 
118
     */
 
119
    QString Owner;
 
120
    /** Tablename.
 
121
     */
 
122
    QString Table;
 
123
    /** The SQL used to read the data.
 
124
     */
 
125
    QString SQL;
 
126
    /** Original values of rows currently being edited.
 
127
     */
 
128
    std::list<QString> OrigValues;
 
129
    /** Original values of rows currently being edited.
 
130
     */
 
131
    bool *BinaryColumns;
 
132
    /** Stream to read data from.
 
133
     */
 
134
    toNoBlockQuery *Query;
 
135
 
 
136
    toQDescList Description;
 
137
    toBackground Poll;
 
138
    int MaxNumber;
 
139
    int SkipNumber;
 
140
    bool GotoEnd;
 
141
    /** Number of rows read from stream.
 
142
     */
 
143
    int Row;
 
144
    /** Current row of editing.
 
145
     */
 
146
    int CurrentRow;
 
147
    /** Current row of editing.
 
148
     */
 
149
    int NewRecordRow;
 
150
    /** Used to detect drag.
 
151
     */
 
152
    QPoint LastMove;
 
153
 
 
154
    /** Popup menu if available.
 
155
     */
 
156
    QPopupMenu *Menu;
 
157
    /** Column of item selected when popup menu displayed.
 
158
     */
 
159
    int MenuColumn;
 
160
    /** Row of item selected when popup menu displayed.
 
161
     */
 
162
    int MenuRow;
 
163
 
 
164
    /** Current sorting row.
 
165
     */
 
166
    int SortRow;
 
167
    /** Indicate if sorting ascending or descending.
 
168
     */
 
169
    bool SortRowAsc;
 
170
 
 
171
    /** Use filter for all tables.
 
172
     */
 
173
    bool AllFilter;
 
174
    /** Filter selection criteria
 
175
     */
 
176
    static std::map<QCString, QString> Criteria;
 
177
    /** Filter retrieve order
 
178
     */
 
179
    static std::map<QCString, QString> Order;
 
180
    /** Current filter name in map
 
181
     */
 
182
    QString FilterName;
 
183
    /** Never use returning.
 
184
     */
 
185
    bool NoUseReturning;
 
186
 
 
187
    /** Throw an exception about wrong usage.
 
188
     */
 
189
    void wrongUsage(void);
 
190
 
 
191
    void saveRow(int);
 
192
    /** Reimplemented for internal reasons.
 
193
     */
 
194
    virtual void drawContents(QPainter * p, int cx, int cy, int cw, int ch);
 
195
    /** Reimplemented for internal reasons.
 
196
     */
 
197
    virtual QWidget *beginEdit(int row, int col, bool replace);
 
198
    virtual void endEdit(int row, int col, bool accept, bool replace);
 
199
 
 
200
    /** Reimplemented for internal reasons.
 
201
     */
 
202
    virtual void paintCell(QPainter *p, int row, int col, const QRect &cr, bool selected);
 
203
    /** Reimplemented for internal reasons.
 
204
    */
 
205
    virtual bool eventFilter(QObject *o, QEvent *e);
 
206
    /** Reimplemented for internal reasons.
 
207
    */
 
208
    virtual void keyPressEvent(QKeyEvent *e);
 
209
    /** Reimplemented for internal reasons.
 
210
     */
 
211
    virtual void activateNextCell();
 
212
 
 
213
    /** Reimplemented for internal reasons.
 
214
     */
 
215
    virtual void dragEnterEvent(QDragEnterEvent *event);
 
216
    /** Reimplemented for internal reasons.
 
217
     */
 
218
    virtual void dropEvent(QDropEvent *event);
 
219
    /** Reimplemented for internal reasons.
 
220
     */
 
221
    virtual void contentsMousePressEvent(QMouseEvent *e);
 
222
    /** Reimplemented for internal reasons.
 
223
     */
 
224
    virtual void contentsMouseReleaseEvent(QMouseEvent *e);
 
225
    /** Reimplemented for internal reasons.
 
226
     */
 
227
    virtual void contentsMouseMoveEvent (QMouseEvent *e);
 
228
    /** Reimplemented for internal reasons.
 
229
     */
 
230
    virtual void focusInEvent (QFocusEvent *e);
 
231
    /** A setCurrentCell() replacement; makes sure that we have focus.
 
232
     */
 
233
    virtual void setCurrentCellFocus(int row, int col);
 
234
 
 
235
    int MaxColDisp;
 
236
 
 
237
    QString table(void);
 
238
 
 
239
    toConnection &connection();
 
240
    QLineEdit *CurrentEditor;
 
241
    int SearchStart;
 
242
    int SearchEnd;
 
243
 
 
244
class contentItem : public QTableItem
 
245
    {
 
246
    public:
 
247
        contentItem(QTable *table, const QString &text);
 
248
        virtual QString key(void) const;
 
249
    };
 
250
 
 
251
    toListView *copySelection(bool);
 
252
public:
 
253
    /** Indicate that editor should never use returning clauses even if this is oracle.
 
254
     */
 
255
    void useNoReturning(bool use)
 
256
    {
 
257
        NoUseReturning = use;
 
258
    }
 
259
    /** Create the widget.
 
260
     * @param parent Parent widget.
 
261
     * @param name Name of widget.
 
262
     */
 
263
    toResultContentEditor(QWidget *parent, const char *name = NULL);
 
264
    /** Destruct object
 
265
     */
 
266
    ~toResultContentEditor();
 
267
    /** Reimplemented for internal reasons.
 
268
     */
 
269
    virtual void query(const QString &, const toQList &);
 
270
    /** Reimplemented for internal reasons.
 
271
     */
 
272
    virtual void changeParams(const QString &Param1, const QString &Param2)
 
273
    {
 
274
        toQList pars;
 
275
        pars.insert(pars.end(), Param1);
 
276
        pars.insert(pars.end(), Param2);
 
277
        query(QString::null, pars);
 
278
    }
 
279
 
 
280
    /** Print this editor.
 
281
     */
 
282
    virtual void editPrint(void);
 
283
    /** Reimplemented for internal reasons.
 
284
     */
 
285
    virtual bool editSave(bool ask);
 
286
    /** Reimplemented for internal reasons.
 
287
     */
 
288
    virtual void editReadAll(void);
 
289
    /** Select all contents. Default NOP.
 
290
     */
 
291
    virtual void editSelectAll(void);
 
292
 
 
293
    /** Reimplemented for internal reasons.
 
294
     */
 
295
    virtual void setText(int row, int col, const QString &text);
 
296
 
 
297
    /** Set a new filter setting.
 
298
     * @param all Apply filter to all tables, otherwise only for this table.
 
299
     * @param criteria Criteria to filter on.
 
300
     * @param order Order to read data on.
 
301
     */
 
302
    void changeFilter(bool all, const QString &criteria, const QString &order);
 
303
 
 
304
    /** Get information about if filter affect all tables.
 
305
     */
 
306
    bool allFilter()
 
307
    {
 
308
        return AllFilter;
 
309
    }
 
310
 
 
311
    friend class contentItem;
 
312
    friend class toResultContent;
 
313
 
 
314
    /** Export data to a map.
 
315
     * @param data A map that can be used to recreate the data of a chart.
 
316
     * @param prefix Prefix to add to the map.
 
317
     */
 
318
    virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix);
 
319
    /** Import data
 
320
     * @param data Data to read from a map.
 
321
     * @param prefix Prefix to read data from.
 
322
     */
 
323
    virtual void importData(std::map<QCString, QString> &data, const QCString &prefix);
 
324
public slots:
 
325
    /** Erase last parameters
 
326
     */
 
327
    virtual void clearParams(void)
 
328
    {
 
329
        Owner = Table = QString::null;
 
330
    }
 
331
    /** Change sorting column
 
332
     * @param col Column selected to change as sorting.
 
333
     */
 
334
    virtual void changeSort(int col);
 
335
    /** Current cell changed.
 
336
     * @param row New row.
 
337
     * @param col New column.
 
338
     */
 
339
    void changePosition(int row, int col);
 
340
 
 
341
    /** Display popup menu
 
342
     * @param p Point to display popup at.
 
343
     */
 
344
    virtual void displayMenu(const QPoint &p);
 
345
    /** Display editable memo viewer at current position.
 
346
     */
 
347
    virtual void displayMemo(void);
 
348
    /** Save unsaved changes in the editor
 
349
     */
 
350
    virtual void saveUnsaved(void);
 
351
    /** Delete the current row from the table.
 
352
     */
 
353
    virtual void deleteCurrent(void);
 
354
    /** Add a new record to the table.
 
355
     */
 
356
    virtual void addRecord(void);
 
357
    /** Duplicate a new record for editing.
 
358
     */
 
359
    virtual void duplicateRecord(void);
 
360
    /** Discard the changes made to the table.
 
361
     */
 
362
    virtual void cancelEdit(void);
 
363
    /** Goto the last record in the table.
 
364
     */
 
365
    virtual void gotoLastRecord(void);
 
366
    /** Goto the first record in the table.
 
367
     */
 
368
    virtual void gotoFirstRecord(void);
 
369
    /** Goto the previous record in the table.
 
370
     */
 
371
    virtual void gotoPreviousRecord(void);
 
372
    /** Goto the next record in the table.
 
373
     */
 
374
    virtual void gotoNextRecord(void);
 
375
    /** Display single record form.
 
376
     */
 
377
    virtual void singleRecordForm(bool display);
 
378
 
 
379
    /** Move to top of data
 
380
     */
 
381
    virtual void searchTop(void)
 
382
    {
 
383
        setCurrentCell(0, 0);
 
384
    }
 
385
    /** Search for next entry
 
386
     * @return True if found, should select the found text.
 
387
     */
 
388
    virtual bool searchNext(toSearchReplace *search);
 
389
    /** Replace entry with new data
 
390
     */
 
391
    virtual void searchReplace(const QString &newData);
 
392
    /** Check if data can be modified by search
 
393
     * @param all If true can replace all, otherwise can replace right now.
 
394
     */
 
395
    virtual bool searchCanReplace(bool all);
 
396
signals:
 
397
    /** Emitted to indicate wether a filter is used.
 
398
     */
 
399
    void filterEnabled(bool);
 
400
    //* Emitted when changes were saved.
 
401
    void changesSaved();
 
402
protected slots:
 
403
    /** Callback from popup menu.
 
404
     * @param cmd Command ID.
 
405
     */
 
406
    virtual void menuCallback(int cmd);
 
407
    /** Change data at specified position.
 
408
     * @param row Row to change.
 
409
     * @param col Column to change.
 
410
     * @param data New contents of data.
 
411
     */
 
412
    virtual void changeData(int row, int col, const QString &data);
 
413
private slots:
 
414
    virtual void poll(void);
 
415
};
 
416
 
 
417
/** This widget allows the user to browse the contents of a table and also edit
 
418
 * the content. The table is specified by the first and second parameter in the query.
 
419
 * The sql is not used in the query.
 
420
 */
 
421
 
 
422
class toResultContent : public QVBox, public toResult
 
423
{
 
424
    Q_OBJECT
 
425
 
 
426
    toResultContentEditor *Editor;
 
427
public:
 
428
    /** Create the widget.
 
429
     * @param parent Parent widget.
 
430
     * @param name Name of widget.
 
431
     */
 
432
    toResultContent(QWidget *parent, const char *name = NULL);
 
433
 
 
434
    /** Get content editor table widget
 
435
     * @return Pointer to editor.
 
436
     */
 
437
    toResultContentEditor *editor(void)
 
438
    {
 
439
        return Editor;
 
440
    }
 
441
 
 
442
    /** Read all rows from the table.
 
443
     */
 
444
    virtual void editReadAll(void)
 
445
    {
 
446
        Editor->editReadAll();
 
447
    }
 
448
    /** Print the contents.
 
449
     */
 
450
    virtual void editPrint(void)
 
451
    {
 
452
        Editor->editPrint();
 
453
    }
 
454
    /** Export contents to file.
 
455
     */
 
456
    virtual void editSave(bool ask)
 
457
    {
 
458
        Editor->editSave(ask);
 
459
    }
 
460
 
 
461
    /** Export data to a map.
 
462
     * @param data A map that can be used to recreate the data of a chart.
 
463
     * @param prefix Prefix to add to the map.
 
464
     */
 
465
    virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix)
 
466
    {
 
467
        Editor->exportData(data, prefix);
 
468
    }
 
469
    /** Import data
 
470
     * @param data Data to read from a map.
 
471
     * @param prefix Prefix to read data from.
 
472
     */
 
473
    virtual void importData(std::map<QCString, QString> &data, const QCString &prefix)
 
474
    {
 
475
        Editor->importData(data, prefix);
 
476
    }
 
477
    /** Indicate that editor should never use returning clauses even if this is oracle.
 
478
     */
 
479
    void useNoReturning(bool use)
 
480
    {
 
481
        Editor->useNoReturning(use);
 
482
    }
 
483
private slots:
 
484
    void changeFilter(void);
 
485
    void removeFilter(void);
 
486
signals:
 
487
    //* Emitted when changes were saved.
 
488
    void changesSaved(void);
 
489
public slots:
 
490
    /** Erase last parameters
 
491
     */
 
492
    virtual void clearParams(void)
 
493
    {
 
494
        toResult::clearParams();
 
495
        Editor->clearParams();
 
496
    }
 
497
    /** Reimplemented for internal reasons.
 
498
     */
 
499
    virtual void refresh(void)
 
500
    {
 
501
        toResult::refresh();
 
502
    }
 
503
    /** Reimplemented for internal reasons.
 
504
     */
 
505
    virtual void query(const QString &sql, const toQList &param)
 
506
    {
 
507
        if (!setSQLParams(sql, param))
 
508
            return ;
 
509
        Editor->query(sql, param);
 
510
    }
 
511
    /** Reimplemented for internal reasons.
 
512
     */
 
513
    virtual void changeParams(const QString &Param1)
 
514
    {
 
515
        toResult::changeParams(Param1);
 
516
    }
 
517
    /** Reimplemented for internal reasons.
 
518
     */
 
519
    virtual void changeParams(const QString &Param1, const QString &Param2)
 
520
    {
 
521
        toResult::changeParams(Param1, Param2);
 
522
    }
 
523
    /** Reimplemented for internal reasons.
 
524
     */
 
525
    virtual void changeParams(const QString &Param1, const QString &Param2, const QString &Param3)
 
526
    {
 
527
        toResult::changeParams(Param1, Param2, Param3);
 
528
    }
 
529
    /** Save unsaved changes in the editor
 
530
     */
 
531
    virtual void saveUnsaved(void)
 
532
    {
 
533
        Editor->saveUnsaved();
 
534
    }
 
535
    /** Commit connection
 
536
     * @param conn Connection commit is made on.
 
537
     * @param cmt If commit or rollback
 
538
     */
 
539
    virtual void saveUnsaved(toConnection &conn, bool cmt);
 
540
 
 
541
    /** Handle all databases
 
542
     */
 
543
    virtual bool canHandle(toConnection &);
 
544
};
 
545
 
 
546
#endif