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

« back to all changes in this revision

Viewing changes to src/toresultview.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 TORESULTVIEW_H
 
39
#define TORESULTVIEW_H
 
40
 
 
41
#include "config.h"
 
42
#include "toeditwidget.h"
 
43
#include "toresult.h"
 
44
#include "toresultlistformatui.h"
 
45
 
 
46
#include <qlistview.h>
 
47
 
 
48
#include <map>
 
49
#include <algorithm>
 
50
 
 
51
class QListViewItem;
 
52
class QPopupMenu;
 
53
class TOPrinter;
 
54
class toListTip;
 
55
class toQuery;
 
56
class toResultCols;
 
57
class toResultView;
 
58
class toSQL;
 
59
class toSearchReplace;
 
60
 
 
61
/** Baseclass for filters to apply to the @ref toResultView to filter out
 
62
 * rows that you don't want to add as items to the list.
 
63
 */
 
64
class toResultFilter
 
65
{
 
66
public:
 
67
    toResultFilter()
 
68
    { }
 
69
    virtual ~toResultFilter()
 
70
    { }
 
71
    virtual void startingQuery(void)
 
72
    { }
 
73
    /** This function can inspect the item to be added and decide if it is
 
74
     * valid for adding or not.
 
75
     * @param item Item to inspect.
 
76
     * @return If false is returned the item isn't added.
 
77
     */
 
78
    virtual bool check(const QListViewItem *item) = 0;
 
79
    /** Create a copy of this filter.
 
80
     * @return A newly created copy of this filter.
 
81
     */
 
82
    virtual toResultFilter *clone(void) = 0;
 
83
    /** Export data to a map.
 
84
     * @param data A map that can be used to recreate the data of a chart.
 
85
     * @param prefix Prefix to add to the map.
 
86
     */
 
87
    virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix);
 
88
    /** Import data
 
89
     * @param data Data to read from a map.
 
90
     * @param prefix Prefix to read data from.
 
91
     */
 
92
    virtual void importData(std::map<QCString, QString> &data, const QCString &prefix);
 
93
};
 
94
 
 
95
/** An item to display in a toListView or toResultView. They differ from normal
 
96
 * QListViewItems in that they can have a tooltip and actually contain more text
 
97
 * than is displayed in the cell of the listview.
 
98
 */
 
99
class toResultViewItem : public QListViewItem
 
100
{
 
101
    struct keyData
 
102
    {
 
103
        QString Data;
 
104
        QString KeyAsc;
 
105
        QString KeyDesc;
 
106
        int Width;
 
107
        enum { String, Number } Type;
 
108
    };
 
109
    int ColumnCount;
 
110
    keyData *ColumnData;
 
111
    QString firstText(int col) const;
 
112
protected:
 
113
    virtual int realWidth(const QFontMetrics &fm, const QListView *top, int column, const QString &txt) const;
 
114
public:
 
115
    /** Create a new item.
 
116
     * @param parent Parent list view.
 
117
     * @param after Insert after this item.
 
118
     * @param buffer String to set as first column
 
119
     */
 
120
    toResultViewItem(QListView *parent, QListViewItem *after, const QString &buf = QString::null)
 
121
            : QListViewItem(parent, after, QString::null)
 
122
    {
 
123
        ColumnData = NULL;
 
124
        ColumnCount = 0;
 
125
        if (buf)
 
126
            setText(0, buf);
 
127
    }
 
128
    /** Create a new item.
 
129
     * @param parent Parent to this item.
 
130
     * @param after Insert after this item.
 
131
     * @param buffer String to set as first column
 
132
     */
 
133
    toResultViewItem(QListViewItem *parent, QListViewItem *after, const QString &buf = QString::null)
 
134
            : QListViewItem(parent, after, QString::null)
 
135
    {
 
136
        ColumnData = NULL;
 
137
        ColumnCount = 0;
 
138
        if (buf)
 
139
            setText(0, buf);
 
140
    }
 
141
    /** Reimplemented for internal reasons.
 
142
     */
 
143
    virtual ~toResultViewItem()
 
144
    {
 
145
        delete[] ColumnData;
 
146
    }
 
147
    /** Reimplemented for internal reasons.
 
148
     */
 
149
    virtual void setText (int col, const QString &txt);
 
150
    /** Set from database.
 
151
     */
 
152
    virtual void setText (int col, const toQValue &val);
 
153
    /** Reimplemented for internal reasons.
 
154
     */
 
155
    virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align);
 
156
    /** Reimplemented for internal reasons.
 
157
     */
 
158
    virtual QString text(int col) const;
 
159
    /** String to sort the data on. This is reimplemented so that numbers are sorted as numbers
 
160
     * and not as strings.
 
161
     * @param col Column
 
162
     * @param asc Wether to sort ascending or not.
 
163
     */
 
164
    virtual QString key(int col, bool asc) const
 
165
    {
 
166
        if (col >= ColumnCount)
 
167
            return QString::null;
 
168
        return asc ? ColumnData[col].KeyAsc : ColumnData[col].KeyDesc;
 
169
    }
 
170
    /** Reimplemented for internal reasons.
 
171
     */
 
172
    virtual int width(const QFontMetrics &, const QListView *, int col) const
 
173
    {
 
174
        if (col >= ColumnCount)
 
175
            return 0;
 
176
        return ColumnData[col].Width;
 
177
    }
 
178
    /** Get all text for this item. This is used for copying, drag & drop and memo editing etc.
 
179
     * @param col Column.
 
180
     * @return All of the text.
 
181
     */
 
182
    virtual QString allText(int col) const
 
183
    {
 
184
        if (col >= ColumnCount)
 
185
            return QString::null;
 
186
        return ColumnData[col].Data;
 
187
    }
 
188
    /** Get the text to be displayed as tooltip for this item.
 
189
     * @param col Column.
 
190
     * @return The text to display as tooltip.
 
191
     */
 
192
    virtual QString tooltip(int col) const
 
193
    {
 
194
        return allText(col);
 
195
    }
 
196
};
 
197
 
 
198
/** This item expands the height to commodate all lines in the input buffer.
 
199
 */
 
200
class toResultViewMLine : public toResultViewItem
 
201
{
 
202
private:
 
203
    /** Number of lines in the largest row.
 
204
     */
 
205
    int Lines;
 
206
protected:
 
207
    virtual int realWidth(const QFontMetrics &fm, const QListView *top, int column, const QString &txt) const;
 
208
public:
 
209
    /** Create a new item.
 
210
     * @param parent Parent list view.
 
211
     * @param after Insert after this item.
 
212
     * @param buffer String to set as first column
 
213
     */
 
214
    toResultViewMLine(QListView *parent, QListViewItem *after, const QString &buf = QString::null)
 
215
            : toResultViewItem(parent, after, QString::null)
 
216
    {
 
217
        Lines = 1;
 
218
        if (buf)
 
219
            setText(0, buf);
 
220
    }
 
221
    /** Create a new item.
 
222
     * @param parent Parent to this item.
 
223
     * @param after Insert after this item.
 
224
     * @param buffer String to set as first column
 
225
     */
 
226
    toResultViewMLine(QListViewItem *parent, QListViewItem *after, const QString &buf = QString::null)
 
227
            : toResultViewItem(parent, after, QString::null)
 
228
    {
 
229
        Lines = 1;
 
230
        if (buf)
 
231
            setText(0, buf);
 
232
    }
 
233
    /** Reimplemented for internal reasons.
 
234
     */
 
235
    virtual void setText (int, const QString &);
 
236
    /** Set from database.
 
237
     */
 
238
    virtual void setText (int col, const toQValue &val);
 
239
    /** Reimplemented for internal reasons.
 
240
     */
 
241
    virtual void setup(void);
 
242
    /** Reimplemented for internal reasons.
 
243
     */
 
244
    virtual QString text(int col) const
 
245
    {
 
246
        return toResultViewItem::allText(col);
 
247
    }
 
248
    /** Reimplemented for internal reasons.
 
249
     */
 
250
    virtual void paintCell (QPainter *pnt, const QColorGroup & cg, int column, int width, int alignment);
 
251
};
 
252
 
 
253
/** An item to display in a toListView or toResultView. They differ from normal
 
254
 * QListViewItems in that they can have a tooltip and actually contain more text
 
255
 * than is displayed in the cell of the listview.
 
256
 */
 
257
class toResultViewCheck : public QCheckListItem
 
258
{
 
259
    struct keyData
 
260
    {
 
261
        QString Data;
 
262
        QString KeyAsc;
 
263
        QString KeyDesc;
 
264
        int Width;
 
265
        enum { String, Number } Type;
 
266
    };
 
267
    int ColumnCount;
 
268
    keyData *ColumnData;
 
269
protected:
 
270
    virtual int realWidth(const QFontMetrics &fm, const QListView *top, int column, const QString &txt) const;
 
271
    QString firstText(int col) const;
 
272
public:
 
273
    /** Create a new item.
 
274
     * @param parent Parent list view.
 
275
     * @param text Text of first column.
 
276
     * @param type Type of check on this item.
 
277
     */
 
278
    toResultViewCheck(QListView *parent, const QString &text, QCheckListItem::Type type = Controller)
 
279
            : QCheckListItem(parent, QString::null, type)
 
280
    {
 
281
        ColumnData = NULL;
 
282
        ColumnCount = 0;
 
283
        if (!text.isNull())
 
284
            setText(0, text);
 
285
    }
 
286
    /** Create a new item.
 
287
     * @param parent Parent item.
 
288
     * @param text Text of first column.
 
289
     * @param type Type of check on this item.
 
290
     */
 
291
    toResultViewCheck(QListViewItem *parent, const QString &text, QCheckListItem::Type type = Controller)
 
292
            : QCheckListItem(parent, QString::null, type)
 
293
    {
 
294
        ColumnData = NULL;
 
295
        ColumnCount = 0;
 
296
        if (!text.isNull())
 
297
            setText(0, text);
 
298
    }
 
299
    /** Create a new item.
 
300
     * @param parent Parent list view.
 
301
     * @param after After last item.
 
302
     * @param text Text of first column.
 
303
     * @param type Type of check on this item.
 
304
     */
 
305
    toResultViewCheck(QListView *parent, QListViewItem *after, const QString &text, QCheckListItem::Type type = Controller);
 
306
    /** Create a new item.
 
307
     * @param parent Parent item.
 
308
     * @param after After last item.
 
309
     * @param text Text of first column.
 
310
     * @param type Type of check on this item.
 
311
     */
 
312
    toResultViewCheck(QListViewItem *parent, QListViewItem *after, const QString &text, QCheckListItem::Type type = Controller);
 
313
    /** Reimplemented for internal reasons.
 
314
     */
 
315
    virtual ~toResultViewCheck()
 
316
    {
 
317
        delete[] ColumnData;
 
318
    }
 
319
    /** Reimplemented for internal reasons.
 
320
     */
 
321
    virtual void setText (int col, const QString &txt);
 
322
    /** Set from database.
 
323
     */
 
324
    virtual void setText (int col, const toQValue &val);
 
325
    /** Reimplemented for internal reasons.
 
326
     */
 
327
    virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align);
 
328
    /** Reimplemented for internal reasons.
 
329
     */
 
330
    virtual QString text(int col) const;
 
331
    /** String to sort the data on. This is reimplemented so that numbers are sorted as numbers
 
332
     * and not as strings.
 
333
     * @param col Column
 
334
     * @param asc Wether to sort ascending or not.
 
335
     */
 
336
    /** String to sort the data on. This is reimplemented so that numbers are sorted as numbers
 
337
     * and not as strings.
 
338
     * @param col Column
 
339
     * @param asc Wether to sort ascending or not.
 
340
     */
 
341
    virtual QString key(int col, bool asc) const
 
342
    {
 
343
        if (col >= ColumnCount)
 
344
            return QString::null;
 
345
        return asc ? ColumnData[col].KeyAsc : ColumnData[col].KeyDesc;
 
346
    }
 
347
    /** Reimplemented for internal reasons.
 
348
     */
 
349
    virtual int width(const QFontMetrics &, const QListView *, int col) const
 
350
    {
 
351
        if (col >= ColumnCount)
 
352
            return 0;
 
353
        return ColumnData[col].Width;
 
354
    }
 
355
    /** Get all text for this item. This is used for copying, drag & drop and memo editing etc.
 
356
     * @param col Column.
 
357
     * @return All of the text.
 
358
     */
 
359
    virtual QString allText(int col) const
 
360
    {
 
361
        if (col >= ColumnCount)
 
362
            return QString::null;
 
363
        return ColumnData[col].Data;
 
364
    }
 
365
    /** Get the text to be displayed as tooltip for this item.
 
366
     * @param col Column.
 
367
     * @return The text to display as tooltip.
 
368
     */
 
369
    virtual QString tooltip(int col) const
 
370
    {
 
371
        return allText(col);
 
372
    }
 
373
};
 
374
 
 
375
/** This item expands the height to commodate all lines in the input buffer.
 
376
 */
 
377
class toResultViewMLCheck : public toResultViewCheck
 
378
{
 
379
private:
 
380
    /** Number of lines in the largest row.
 
381
     */
 
382
    int Lines;
 
383
protected:
 
384
    virtual int realWidth(const QFontMetrics &fm, const QListView *top, int column, const QString &txt) const;
 
385
public:
 
386
    /** Create a new item.
 
387
     * @param parent Parent list view.
 
388
     * @param text Text of first column.
 
389
     * @param type Type of check on this item.
 
390
     */
 
391
    toResultViewMLCheck(QListView *parent, const QString &text, QCheckListItem::Type type = Controller)
 
392
            : toResultViewCheck(parent, QString::null, type)
 
393
    {
 
394
        Lines = 1;
 
395
        if (!text.isNull())
 
396
            setText(0, text);
 
397
    }
 
398
    /** Create a new item.
 
399
     * @param parent Parent item.
 
400
     * @param text Text of first column.
 
401
     * @param type Type of check on this item.
 
402
     */
 
403
    toResultViewMLCheck(QListViewItem *parent, const QString &text, QCheckListItem::Type type = Controller)
 
404
            : toResultViewCheck(parent, QString::null, type)
 
405
    {
 
406
        Lines = 1;
 
407
        if (!text.isNull())
 
408
            setText(0, text);
 
409
    }
 
410
    /** Reimplemented for internal reasons.
 
411
     */
 
412
    virtual void setup(void);
 
413
    /** Reimplemented for internal reasons.
 
414
     */
 
415
    virtual void setText (int, const QString &);
 
416
    /** Set from database.
 
417
     */
 
418
    virtual void setText (int col, const toQValue &val);
 
419
    /** Reimplemented for internal reasons.
 
420
     */
 
421
    virtual QString text(int col) const
 
422
    {
 
423
        return toResultViewCheck::allText(col);
 
424
    }
 
425
    /** Reimplemented for internal reasons.
 
426
     */
 
427
    virtual void paintCell (QPainter *pnt, const QColorGroup & cg, int column, int width, int alignment);
 
428
};
 
429
 
 
430
/**
 
431
 * The TOra implementation of a listview which offers a few extra goodies to the baseclass.
 
432
 * First of all tooltip which can display contents that doesn't fit in the list, printing,
 
433
 * integration into toMain with Edit menu etc, drag & drop, export as file, display item
 
434
 * as memo and context menu.
 
435
 */
 
436
class toListView : public QListView, public toEditWidget
 
437
{
 
438
    Q_OBJECT
 
439
 
 
440
    bool FirstSearch;
 
441
 
 
442
    /** Name of this list, used primarily when printing. Also used to be able to edit
 
443
     * SQL displayed in @ref toResultView.
 
444
     */
 
445
    QString Name;
 
446
    /** Used to display tip on fields.
 
447
     */
 
448
    toListTip *AllTip;
 
449
    /** Item selected when popup menu displayed.
 
450
     */
 
451
    QListViewItem *MenuItem;
 
452
    /** Column of item selected when popup menu displayed.
 
453
     */
 
454
    int MenuColumn;
 
455
    /** Popup menu if available.
 
456
     */
 
457
    QPopupMenu *Menu;
 
458
    /** Last move, used to determine if drag has started.
 
459
     */
 
460
    QPoint LastMove;
 
461
 
 
462
    /** Reimplemented for internal reasons.
 
463
     */
 
464
    virtual void contentsMouseDoubleClickEvent (QMouseEvent *e);
 
465
    /** Reimplemented for internal reasons.
 
466
     */
 
467
    virtual void contentsMousePressEvent(QMouseEvent *e);
 
468
    /** Reimplemented for internal reasons.
 
469
     */
 
470
    virtual void contentsMouseReleaseEvent(QMouseEvent *e);
 
471
    /** Reimplemented for internal reasons.
 
472
     */
 
473
    virtual void contentsMouseMoveEvent (QMouseEvent *e);
 
474
 
 
475
    /** Used to print one page of the list.
 
476
     * @param printer Printer to print to.
 
477
     * @param painter Painter to print page to.
 
478
     * @param top Item at top of page.
 
479
     * @param column Column to start printing at. Will be changed to where you are when done.
 
480
     * @param level The indentation level of the top item.
 
481
     * @param pageNo Page number.
 
482
     * @param paint If just testing to determine how many pages are needed set this to false.
 
483
     * @return The next item to print to (Pass as top to this function).
 
484
     */
 
485
    virtual QListViewItem *printPage(TOPrinter *printer, QPainter *painter, QListViewItem *top,
 
486
                                     int &column, int &level, int pageNo, bool paint = true);
 
487
    int exportType(QString &separator, QString &delimiter);
 
488
 
 
489
    QString owner;
 
490
    QString objectName;
 
491
 
 
492
    bool includeHeader;
 
493
    bool onlySelection;
 
494
    QString sep;
 
495
    QString del;
 
496
 
 
497
public:
 
498
     bool getIncludeHeader(){return includeHeader;};
 
499
     bool getOnlySelection(){return onlySelection;};
 
500
     QString getSep(){return sep;};
 
501
     QString getDel(){return del;};
 
502
 
 
503
    /** Create new list view.
 
504
     * @param parent Parent of list.
 
505
     * @param name Name of list.
 
506
     * @param f Widget flags.
 
507
     */
 
508
    toListView(QWidget *parent, const char *name = NULL, WFlags f = 0);
 
509
    virtual ~toListView();
 
510
 
 
511
    /** Get SQL name of list.
 
512
     */
 
513
    virtual QString sqlName(void)
 
514
    {
 
515
        return Name;
 
516
    }
 
517
    /** Set SQL name of list.
 
518
     */
 
519
    virtual void setSQLName(const QString &name)
 
520
    {
 
521
        Name = name;
 
522
    }
 
523
 
 
524
    /** Set owner
 
525
     * introduced to get type information for fields
 
526
     */
 
527
    virtual void setOwner(QString const & tOwner)
 
528
    {
 
529
        owner = tOwner;
 
530
    }
 
531
 
 
532
 
 
533
    /** Set object name 
 
534
     * introduced to get type information for fields
 
535
     */
 
536
    virtual void setObjectName(QString const & tObjectName)
 
537
    {
 
538
        objectName = tObjectName;
 
539
    }
 
540
 
 
541
    /** Get owner
 
542
     * introduced to get type information for fields
 
543
     */
 
544
    virtual QString getOwner()
 
545
    {
 
546
        return owner;
 
547
    }
 
548
 
 
549
 
 
550
    /** Get object name 
 
551
     * introduced to get type information for fields
 
552
     */
 
553
    virtual QString getObjectName()
 
554
    {
 
555
        return objectName;
 
556
    }
 
557
 
 
558
    /** Get the whole text for the item and column selected when menu was poped up.
 
559
     */
 
560
    QString menuText(void);
 
561
 
 
562
    /** Print this list
 
563
     */
 
564
    virtual void editPrint(void);
 
565
    /** Reimplemented for internal reasons.
 
566
     */
 
567
    virtual void focusInEvent (QFocusEvent *e);
 
568
    /** The string to be displayed in the middle of the footer when printing.
 
569
     * @return String to be placed in middle.
 
570
     */
 
571
    virtual QString middleString()
 
572
    {
 
573
        return QString::null;
 
574
    }
 
575
    /** Adds option to add menues to the popup menu before it is displayed.
 
576
     * @param menu Menu to add entries to.
 
577
     */
 
578
    virtual void addMenues(QPopupMenu *menu);
 
579
    /** Export list as a string.
 
580
     * @param includeHeader Include header.
 
581
     * @param onlySelection Only include selection.
 
582
     * @param type Format of exported list.
 
583
     * @param separator Separator for CSV format.
 
584
     * @param delimiter Delimiter for CSV format.
 
585
     */
 
586
    virtual QString exportAsText(bool includeHeader, bool onlySelection, int type = -1, const QString &separator = ";", const QString &delimiter = "\"");
 
587
    /** Export list as file.
 
588
     */
 
589
    virtual bool editSave(bool ask);
 
590
 
 
591
    /** Select all contents.
 
592
     */
 
593
    virtual void editSelectAll(void)
 
594
    {
 
595
        selectAll(true);
 
596
    }
 
597
 
 
598
    /** Move to top of data
 
599
     */
 
600
    virtual void searchTop(void)
 
601
    {
 
602
        if (firstChild())
 
603
            setCurrentItem(firstChild());
 
604
        FirstSearch = true;
 
605
    }
 
606
    /** Search for next entry
 
607
     * @return True if found, should select the found text.
 
608
     */
 
609
    virtual bool searchNext(toSearchReplace *search);
 
610
    /** Check if data can be modified by search
 
611
     * @param all If true can replace all, otherwise can replace right now.
 
612
     */
 
613
    virtual bool searchCanReplace(bool all);
 
614
 
 
615
    /** Export data to a map.
 
616
     * @param data A map that can be used to recreate the data of a chart.
 
617
     * @param prefix Prefix to add to the map.
 
618
     */
 
619
    virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix);
 
620
    /** Import data
 
621
     * @param data Data to read from a map.
 
622
     * @param prefix Prefix to read data from.
 
623
     */
 
624
    virtual void importData(std::map<QCString, QString> &data, const QCString &prefix);
 
625
    /** Create transposed copy of list
 
626
     * @return Pointer to newly allocated transposed listview.
 
627
     */
 
628
    virtual toListView *copyTransposed(void);
 
629
signals:
 
630
    /** Called before the menu is displayed so that you can add items to it before it is shown.
 
631
     * @param menu Pointer to the menu about to be shown.
 
632
     */
 
633
    void displayMenu(QPopupMenu *menu);
 
634
public slots:
 
635
    /** set the popup menu --> see displayMenu()
 
636
     * @param item Item to display.
 
637
     */
 
638
    virtual void setDisplayMenu(QPopupMenu *item);
 
639
    /** Display the menu at the given point and column.
 
640
     * @param item Item to display.
 
641
     * @param pnt Point to display menu at.
 
642
     * @param col Column to display menu for.
 
643
     */
 
644
    virtual void displayMenu(QListViewItem *item, const QPoint &pnt, int col);
 
645
    /** Display memo of selected menu column
 
646
     */
 
647
    virtual void displayMemo(void);
 
648
protected slots:
 
649
    /** Callback when menu is selected. If you override this make sure you
 
650
     * call the parents function when you have parsed your entries.
 
651
     * @param id ID of the menu item selected.
 
652
     */
 
653
    virtual void menuCallback(int id);
 
654
};
 
655
 
 
656
/**
 
657
 * This class defines a list which displays the result of a query.
 
658
 *
 
659
 * One special thing to know about this class is that columns at the end in which the
 
660
 * description start with a '-' characters are not displayed.
 
661
 */
 
662
 
 
663
class toResultView : public toListView, public toResult
 
664
{
 
665
    Q_OBJECT
 
666
 
 
667
    int SortColumn;
 
668
    bool SortAscending;
 
669
    bool SortConnected;
 
670
 
 
671
    /** Reimplemented for internal reasons.
 
672
     */
 
673
    virtual void keyPressEvent (QKeyEvent * e);
 
674
protected:
 
675
    /** Connection to execute statement on.
 
676
     */
 
677
    toQuery *Query;
 
678
    /** Last added item.
 
679
     */
 
680
    QListViewItem *LastItem;
 
681
 
 
682
    /** Number of rows in list.
 
683
     */
 
684
    int RowNumber;
 
685
    /** If column names are to be made more readable.
 
686
     */
 
687
    bool ReadableColumns;
 
688
    /** Wether to display first number column or not.
 
689
     */
 
690
    bool NumberColumn;
 
691
    /** If all the available data should be read at once.
 
692
     */
 
693
    bool ReadAll;
 
694
    /** Input filter if any.
 
695
     */
 
696
    toResultFilter *Filter;
 
697
 
 
698
    /** Setup the list.
 
699
     * @param readable Wether to display first number column or not.
 
700
     * @param dispCol Wether to display first number column or not.
 
701
     */
 
702
    void setup(bool readable, bool dispCol);
 
703
 
 
704
    /** Check if end of query is detected yet or not.
 
705
     */
 
706
    virtual bool eof(void);
 
707
 
 
708
public:
 
709
    /** Create list.
 
710
     * @param readable Indicate if columns are to be made more readable. This means that the
 
711
     * descriptions are capitalised and '_' are converted to ' '.
 
712
     * @param numCol If number column is to be displayed.
 
713
     * @param parent Parent of list.
 
714
     * @param name Name of widget.
 
715
     * @param f Widget flags.
 
716
     */
 
717
    toResultView(bool readable, bool numCol, QWidget *parent, const char *name = NULL, WFlags f = 0);
 
718
    /** Create list. The columns are not readable and the number column is displayed.
 
719
     * @param parent Parent of list.
 
720
     * @param name Name of widget.
 
721
     * @param f Widget flags.
 
722
     */
 
723
    toResultView(QWidget *parent, const char *name = NULL, WFlags f = 0);
 
724
    ~toResultView();
 
725
 
 
726
    /** Set the read all flag.
 
727
     * @param all New value of flag.
 
728
     */
 
729
    void setReadAll(bool all)
 
730
    {
 
731
        ReadAll = all;
 
732
    }
 
733
 
 
734
    /** Get read all flag
 
735
     * @return Value of read all flag.
 
736
     */
 
737
    virtual void editReadAll(void);
 
738
 
 
739
    /** Get the number of columns in query.
 
740
     * @return Columns in query.
 
741
     */
 
742
    int queryColumns() const;
 
743
 
 
744
    /** Get the query used to execute this.
 
745
     */
 
746
    toQuery *query()
 
747
    {
 
748
        return Query;
 
749
    }
 
750
 
 
751
    /** Set a filter to this list.
 
752
     * @param filter The new filter or NULL if no filter is to be used.
 
753
     */
 
754
    void setFilter(toResultFilter *filter)
 
755
    {
 
756
        Filter = filter;
 
757
    }
 
758
    /** Get the current filter.
 
759
     * @return Current filter or NULL if no filter.
 
760
     */
 
761
    toResultFilter *filter(void)
 
762
    {
 
763
        return Filter;
 
764
    }
 
765
 
 
766
    /** Get number column flag.
 
767
     * @return Wether or not the numbercolumn is displayed.
 
768
     */
 
769
    bool numberColumn() const
 
770
    {
 
771
        return NumberColumn;
 
772
    }
 
773
    /** Set number column flag. Don't change this while a query is running. Observe
 
774
     * that not all descendants of this class support changing this on the fly. The base
 
775
     * class and @ref toResultLong does though.
 
776
     * @param val New value of number column.
 
777
     */
 
778
    void setNumberColumn(bool val)
 
779
    {
 
780
        NumberColumn = val;
 
781
    }
 
782
 
 
783
    /** Get readable column flag.
 
784
     * @return Wether or not the readable column names.
 
785
     */
 
786
    bool readableColumn() const
 
787
    {
 
788
        return ReadableColumns;
 
789
    }
 
790
    /** Set readable column flag.
 
791
     */
 
792
    void setReadableColumns(bool val)
 
793
    {
 
794
        ReadableColumns = val;
 
795
    }
 
796
 
 
797
    /** Create a new item in this list. Can be used if a special kind of item is wanted
 
798
     * in the list. The rest of the columns will be filled with setText.
 
799
     * @param last Where to insert the item.
 
800
     * @param str String to set first column to.
 
801
     * @return Allocated item.
 
802
     */
 
803
    virtual QListViewItem *createItem(QListViewItem *last, const QString &str);
 
804
 
 
805
    /** Reimplemented for internal reasons.
 
806
     */
 
807
    virtual void query(const QString &sql, const toQList &param);
 
808
 
 
809
    /** Get SQL name of list.
 
810
     */
 
811
    virtual QString sqlName(void)
 
812
    {
 
813
        return toListView::sqlName();
 
814
    }
 
815
    /** Set SQL name of list.
 
816
     */
 
817
    virtual void setSQLName(const QString &name)
 
818
    {
 
819
        toListView::setSQLName(name);
 
820
    }
 
821
 
 
822
    // Why are these needed?
 
823
#if 1
 
824
    /** Set the SQL statement of this list
 
825
     * @param sql String containing statement.
 
826
     */
 
827
    void setSQL(const QString &sql)
 
828
    {
 
829
        toResult::setSQL(sql);
 
830
    }
 
831
    /** Set the SQL statement of this list. This will also affect @ref Name.
 
832
     * @param sql SQL containing statement.
 
833
     */
 
834
    void setSQL(const toSQL &sql)
 
835
    {
 
836
        toResult::setSQL(sql);
 
837
    }
 
838
    /** Set new SQL and run query.
 
839
     * @param sql New sql.
 
840
     * @see setSQL
 
841
     */
 
842
    void query(const QString &sql)
 
843
    {
 
844
        toResult::query(sql);
 
845
    }
 
846
    /** Set new SQL and run query.
 
847
     * @param sql New sql.
 
848
     * @see setSQL
 
849
     */
 
850
    void query(const toSQL &sql)
 
851
    {
 
852
        toResult::query(sql);
 
853
    }
 
854
    /** Set new SQL and run query.
 
855
     * @param sql New sql.
 
856
     * @see setSQL
 
857
     */
 
858
    void query(const toSQL &sql, toQList &par)
 
859
    {
 
860
        toResult::query(sql, par);
 
861
    }
 
862
#endif
 
863
 
 
864
    /** Reimplemented for internal reasons.
 
865
     */
 
866
    virtual void editPrint(void)
 
867
    {
 
868
        editReadAll();
 
869
        toListView::editPrint();
 
870
    }
 
871
    /** Reimplemented for internal reasons.
 
872
     */
 
873
    virtual QString middleString();
 
874
 
 
875
    /** Reimplemented for internal reasons.
 
876
     */
 
877
    virtual void addMenues(QPopupMenu *);
 
878
    /** Reimplemented for internal reasons.
 
879
     */
 
880
    virtual void setSorting(int col, bool asc = true);
 
881
    /** Reimplemented for internal reasons.
 
882
     */
 
883
    virtual int sortColumn() const
 
884
    {
 
885
        return SortColumn;
 
886
    }
 
887
public slots:
 
888
    /** Reimplemented for internal reasons.
 
889
     */
 
890
    virtual void refresh(void);
 
891
    /** Reimplemented for internal reasons.
 
892
     */
 
893
    virtual void changeParams(const QString &Param1)
 
894
    {
 
895
        toResult::changeParams(Param1);
 
896
    }
 
897
    /** Reimplemented For internal reasons.
 
898
     */
 
899
    virtual void changeParams(const QString &Param1, const QString &Param2)
 
900
    {
 
901
        toResult::changeParams(Param1, Param2);
 
902
    }
 
903
    /** Reimplemented for internal reasons.
 
904
     */
 
905
    virtual void changeParams(const QString &Param1, const QString &Param2, const QString &Param3)
 
906
    {
 
907
        toResult::changeParams(Param1, Param2, Param3);
 
908
    }
 
909
    /** Try to add an item to the list if available.
 
910
     */
 
911
    virtual void addItem(void);
 
912
    /** Handle any connection by default
 
913
     */
 
914
    virtual bool canHandle(toConnection &)
 
915
    {
 
916
        return true;
 
917
    }
 
918
private slots:
 
919
    void headingClicked(int col);
 
920
    void checkHeading(void);
 
921
protected slots:
 
922
    /** Reimplemented for internal reasons.
 
923
     */
 
924
    virtual void menuCallback(int);
 
925
};
 
926
 
 
927
/***
 
928
 * Used internally by toListView.
 
929
 * @internal
 
930
 */
 
931
 
 
932
class toResultListFormat : public toResultListFormatUI
 
933
{
 
934
    Q_OBJECT
 
935
public:
 
936
    toResultListFormat(QWidget *parent, const char *name);
 
937
    void saveDefault(void);
 
938
public slots:
 
939
    virtual void formatChanged(int pos);
 
940
};
 
941
 
 
942
#endif