[go: up one dir, main page]

File: toresultcontent.h

package info (click to toggle)
tora 1.3.23-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 15,984 kB
  • ctags: 14,460
  • sloc: cpp: 123,554; sh: 16,181; makefile: 966; xml: 69
file content (546 lines) | stat: -rw-r--r-- 15,211 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
/*****
*
* TOra - An Oracle Toolkit for DBA's and developers
* Copyright (C) 2003-2005 Quest Software, Inc
* Portions Copyright (C) 2005 Other Contributors
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation;  only version 2 of
* the License is valid for this program.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*
*      As a special exception, you have permission to link this program
*      with the Oracle Client libraries and distribute executables, as long
*      as you follow the requirements of the GNU GPL in regard to all of the
*      software in the executable aside from Oracle client libraries.
*
*      Specifically you are not permitted to link this program with the
*      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
*      And you are not permitted to distribute binaries compiled against
*      these libraries without written consent from Quest Software, Inc.
*      Observe that this does not disallow linking to the Qt Free Edition.
*
*      You may link this product with any GPL'd Qt library such as Qt/Free
*
* All trademarks belong to their respective owners.
*
*****/

#ifndef TORESULTCONTENT_H
#define TORESULTCONTENT_H

#include "config.h"
#include "tobackground.h"
#include "toconnection.h"
#include "toeditwidget.h"
#include "tomemoeditor.h"
#include "toresult.h"

#include <list>
#include <algorithm>

#include <qtable.h>
#include <qvbox.h>

class QChecBox;
class QCheckBox;
class QGrid;
class QLineEdit;
class toNoBlockQuery;
class toResultContent;
class toSearchReplace;

/** Implement memo editor in result content editor. Only for internal use.
 * @internal
 */

class toResultContentMemo : public toMemoEditor
{
    Q_OBJECT

    toResultContentEditor *contentEditor();
public:
    toResultContentMemo(QWidget *parent, const QString &data, int row, int col,
                        bool sql = false);
public slots:
    virtual void firstColumn();
    virtual void nextColumn();
    virtual void previousColumn();
    virtual void lastColumn();

    virtual void changePosition(int row, int cols);
};

/** This widget is used for single record view in the content editor. Only for internal use.
 * @internal
 */

class toResultContentSingle : public QScrollView
{
    Q_OBJECT

    int Row;
    QGrid *Container;
    std::list<QCheckBox *> Null;
    std::list<QLineEdit *> Value;
public:
    toResultContentSingle(QWidget *parent);

    void changeSource(QTable *table);
    void changeRow(QTable *table, int row);
    void saveRow(QTable *table, int row);
private slots:
    virtual void showMemo(int row);
};

/** This widget allows the user to browse the contents of a table and also edit
 * the content. The table is specified by the first and second parameter in the query.
 * The sql is not used in the query. Only for internal use.
 */

class toResultContentEditor : public QTable, public toEditWidget
{
    Q_OBJECT

    /** Single record form.
     */
    toResultContentSingle *SingleEdit;
    /** Owner of table.
     */
    QString Owner;
    /** Tablename.
     */
    QString Table;
    /** The SQL used to read the data.
     */
    QString SQL;
    /** Original values of rows currently being edited.
     */
    std::list<QString> OrigValues;
    /** Original values of rows currently being edited.
     */
    bool *BinaryColumns;
    /** Stream to read data from.
     */
    toNoBlockQuery *Query;

    toQDescList Description;
    toBackground Poll;
    int MaxNumber;
    int SkipNumber;
    bool GotoEnd;
    /** Number of rows read from stream.
     */
    int Row;
    /** Current row of editing.
     */
    int CurrentRow;
    /** Current row of editing.
     */
    int NewRecordRow;
    /** Used to detect drag.
     */
    QPoint LastMove;

    /** Popup menu if available.
     */
    QPopupMenu *Menu;
    /** Column of item selected when popup menu displayed.
     */
    int MenuColumn;
    /** Row of item selected when popup menu displayed.
     */
    int MenuRow;

    /** Current sorting row.
     */
    int SortRow;
    /** Indicate if sorting ascending or descending.
     */
    bool SortRowAsc;

    /** Use filter for all tables.
     */
    bool AllFilter;
    /** Filter selection criteria
     */
    static std::map<QCString, QString> Criteria;
    /** Filter retrieve order
     */
    static std::map<QCString, QString> Order;
    /** Current filter name in map
     */
    QString FilterName;
    /** Never use returning.
     */
    bool NoUseReturning;

    /** Throw an exception about wrong usage.
     */
    void wrongUsage(void);

    void saveRow(int);
    /** Reimplemented for internal reasons.
     */
    virtual void drawContents(QPainter * p, int cx, int cy, int cw, int ch);
    /** Reimplemented for internal reasons.
     */
    virtual QWidget *beginEdit(int row, int col, bool replace);
    virtual void endEdit(int row, int col, bool accept, bool replace);

    /** Reimplemented for internal reasons.
     */
    virtual void paintCell(QPainter *p, int row, int col, const QRect &cr, bool selected);
    /** Reimplemented for internal reasons.
    */
    virtual bool eventFilter(QObject *o, QEvent *e);
    /** Reimplemented for internal reasons.
    */
    virtual void keyPressEvent(QKeyEvent *e);
    /** Reimplemented for internal reasons.
     */
    virtual void activateNextCell();

    /** Reimplemented for internal reasons.
     */
    virtual void dragEnterEvent(QDragEnterEvent *event);
    /** Reimplemented for internal reasons.
     */
    virtual void dropEvent(QDropEvent *event);
    /** Reimplemented for internal reasons.
     */
    virtual void contentsMousePressEvent(QMouseEvent *e);
    /** Reimplemented for internal reasons.
     */
    virtual void contentsMouseReleaseEvent(QMouseEvent *e);
    /** Reimplemented for internal reasons.
     */
    virtual void contentsMouseMoveEvent (QMouseEvent *e);
    /** Reimplemented for internal reasons.
     */
    virtual void focusInEvent (QFocusEvent *e);
    /** A setCurrentCell() replacement; makes sure that we have focus.
     */
    virtual void setCurrentCellFocus(int row, int col);

    int MaxColDisp;

    QString table(void);

    toConnection &connection();
    QLineEdit *CurrentEditor;
    int SearchStart;
    int SearchEnd;

class contentItem : public QTableItem
    {
    public:
        contentItem(QTable *table, const QString &text);
        virtual QString key(void) const;
    };

    toListView *copySelection(bool);
public:
    /** Indicate that editor should never use returning clauses even if this is oracle.
     */
    void useNoReturning(bool use)
    {
        NoUseReturning = use;
    }
    /** Create the widget.
     * @param parent Parent widget.
     * @param name Name of widget.
     */
    toResultContentEditor(QWidget *parent, const char *name = NULL);
    /** Destruct object
     */
    ~toResultContentEditor();
    /** Reimplemented for internal reasons.
     */
    virtual void query(const QString &, const toQList &);
    /** Reimplemented for internal reasons.
     */
    virtual void changeParams(const QString &Param1, const QString &Param2)
    {
        toQList pars;
        pars.insert(pars.end(), Param1);
        pars.insert(pars.end(), Param2);
        query(QString::null, pars);
    }

    /** Print this editor.
     */
    virtual void editPrint(void);
    /** Reimplemented for internal reasons.
     */
    virtual bool editSave(bool ask);
    /** Reimplemented for internal reasons.
     */
    virtual void editReadAll(void);
    /** Select all contents. Default NOP.
     */
    virtual void editSelectAll(void);

    /** Reimplemented for internal reasons.
     */
    virtual void setText(int row, int col, const QString &text);

    /** Set a new filter setting.
     * @param all Apply filter to all tables, otherwise only for this table.
     * @param criteria Criteria to filter on.
     * @param order Order to read data on.
     */
    void changeFilter(bool all, const QString &criteria, const QString &order);

    /** Get information about if filter affect all tables.
     */
    bool allFilter()
    {
        return AllFilter;
    }

    friend class contentItem;
    friend class toResultContent;

    /** Export data to a map.
     * @param data A map that can be used to recreate the data of a chart.
     * @param prefix Prefix to add to the map.
     */
    virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix);
    /** Import data
     * @param data Data to read from a map.
     * @param prefix Prefix to read data from.
     */
    virtual void importData(std::map<QCString, QString> &data, const QCString &prefix);
public slots:
    /** Erase last parameters
     */
    virtual void clearParams(void)
    {
        Owner = Table = QString::null;
    }
    /** Change sorting column
     * @param col Column selected to change as sorting.
     */
    virtual void changeSort(int col);
    /** Current cell changed.
     * @param row New row.
     * @param col New column.
     */
    void changePosition(int row, int col);

    /** Display popup menu
     * @param p Point to display popup at.
     */
    virtual void displayMenu(const QPoint &p);
    /** Display editable memo viewer at current position.
     */
    virtual void displayMemo(void);
    /** Save unsaved changes in the editor
     */
    virtual void saveUnsaved(void);
    /** Delete the current row from the table.
     */
    virtual void deleteCurrent(void);
    /** Add a new record to the table.
     */
    virtual void addRecord(void);
    /** Duplicate a new record for editing.
     */
    virtual void duplicateRecord(void);
    /** Discard the changes made to the table.
     */
    virtual void cancelEdit(void);
    /** Goto the last record in the table.
     */
    virtual void gotoLastRecord(void);
    /** Goto the first record in the table.
     */
    virtual void gotoFirstRecord(void);
    /** Goto the previous record in the table.
     */
    virtual void gotoPreviousRecord(void);
    /** Goto the next record in the table.
     */
    virtual void gotoNextRecord(void);
    /** Display single record form.
     */
    virtual void singleRecordForm(bool display);

    /** Move to top of data
     */
    virtual void searchTop(void)
    {
        setCurrentCell(0, 0);
    }
    /** Search for next entry
     * @return True if found, should select the found text.
     */
    virtual bool searchNext(toSearchReplace *search);
    /** Replace entry with new data
     */
    virtual void searchReplace(const QString &newData);
    /** Check if data can be modified by search
     * @param all If true can replace all, otherwise can replace right now.
     */
    virtual bool searchCanReplace(bool all);
signals:
    /** Emitted to indicate wether a filter is used.
     */
    void filterEnabled(bool);
    //* Emitted when changes were saved.
    void changesSaved();
protected slots:
    /** Callback from popup menu.
     * @param cmd Command ID.
     */
    virtual void menuCallback(int cmd);
    /** Change data at specified position.
     * @param row Row to change.
     * @param col Column to change.
     * @param data New contents of data.
     */
    virtual void changeData(int row, int col, const QString &data);
private slots:
    virtual void poll(void);
};

/** This widget allows the user to browse the contents of a table and also edit
 * the content. The table is specified by the first and second parameter in the query.
 * The sql is not used in the query.
 */

class toResultContent : public QVBox, public toResult
{
    Q_OBJECT

    toResultContentEditor *Editor;
public:
    /** Create the widget.
     * @param parent Parent widget.
     * @param name Name of widget.
     */
    toResultContent(QWidget *parent, const char *name = NULL);

    /** Get content editor table widget
     * @return Pointer to editor.
     */
    toResultContentEditor *editor(void)
    {
        return Editor;
    }

    /** Read all rows from the table.
     */
    virtual void editReadAll(void)
    {
        Editor->editReadAll();
    }
    /** Print the contents.
     */
    virtual void editPrint(void)
    {
        Editor->editPrint();
    }
    /** Export contents to file.
     */
    virtual void editSave(bool ask)
    {
        Editor->editSave(ask);
    }

    /** Export data to a map.
     * @param data A map that can be used to recreate the data of a chart.
     * @param prefix Prefix to add to the map.
     */
    virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix)
    {
        Editor->exportData(data, prefix);
    }
    /** Import data
     * @param data Data to read from a map.
     * @param prefix Prefix to read data from.
     */
    virtual void importData(std::map<QCString, QString> &data, const QCString &prefix)
    {
        Editor->importData(data, prefix);
    }
    /** Indicate that editor should never use returning clauses even if this is oracle.
     */
    void useNoReturning(bool use)
    {
        Editor->useNoReturning(use);
    }
private slots:
    void changeFilter(void);
    void removeFilter(void);
signals:
    //* Emitted when changes were saved.
    void changesSaved(void);
public slots:
    /** Erase last parameters
     */
    virtual void clearParams(void)
    {
        toResult::clearParams();
        Editor->clearParams();
    }
    /** Reimplemented for internal reasons.
     */
    virtual void refresh(void)
    {
        toResult::refresh();
    }
    /** Reimplemented for internal reasons.
     */
    virtual void query(const QString &sql, const toQList &param)
    {
        if (!setSQLParams(sql, param))
            return ;
        Editor->query(sql, param);
    }
    /** Reimplemented for internal reasons.
     */
    virtual void changeParams(const QString &Param1)
    {
        toResult::changeParams(Param1);
    }
    /** Reimplemented for internal reasons.
     */
    virtual void changeParams(const QString &Param1, const QString &Param2)
    {
        toResult::changeParams(Param1, Param2);
    }
    /** Reimplemented for internal reasons.
     */
    virtual void changeParams(const QString &Param1, const QString &Param2, const QString &Param3)
    {
        toResult::changeParams(Param1, Param2, Param3);
    }
    /** Save unsaved changes in the editor
     */
    virtual void saveUnsaved(void)
    {
        Editor->saveUnsaved();
    }
    /** Commit connection
     * @param conn Connection commit is made on.
     * @param cmt If commit or rollback
     */
    virtual void saveUnsaved(toConnection &conn, bool cmt);

    /** Handle all databases
     */
    virtual bool canHandle(toConnection &);
};

#endif