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.
38
#ifndef TORESULTVIEW_H
39
#define TORESULTVIEW_H
42
#include "toeditwidget.h"
44
#include "toresultlistformatui.h"
46
#include <qlistview.h>
59
class toSearchReplace;
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.
69
virtual ~toResultFilter()
71
virtual void startingQuery(void)
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.
78
virtual bool check(const QListViewItem *item) = 0;
79
/** Create a copy of this filter.
80
* @return A newly created copy of this filter.
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.
87
virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix);
89
* @param data Data to read from a map.
90
* @param prefix Prefix to read data from.
92
virtual void importData(std::map<QCString, QString> &data, const QCString &prefix);
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.
99
class toResultViewItem : public QListViewItem
107
enum { String, Number } Type;
111
QString firstText(int col) const;
113
virtual int realWidth(const QFontMetrics &fm, const QListView *top, int column, const QString &txt) const;
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
120
toResultViewItem(QListView *parent, QListViewItem *after, const QString &buf = QString::null)
121
: QListViewItem(parent, after, QString::null)
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
133
toResultViewItem(QListViewItem *parent, QListViewItem *after, const QString &buf = QString::null)
134
: QListViewItem(parent, after, QString::null)
141
/** Reimplemented for internal reasons.
143
virtual ~toResultViewItem()
147
/** Reimplemented for internal reasons.
149
virtual void setText (int col, const QString &txt);
150
/** Set from database.
152
virtual void setText (int col, const toQValue &val);
153
/** Reimplemented for internal reasons.
155
virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align);
156
/** Reimplemented for internal reasons.
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.
162
* @param asc Wether to sort ascending or not.
164
virtual QString key(int col, bool asc) const
166
if (col >= ColumnCount)
167
return QString::null;
168
return asc ? ColumnData[col].KeyAsc : ColumnData[col].KeyDesc;
170
/** Reimplemented for internal reasons.
172
virtual int width(const QFontMetrics &, const QListView *, int col) const
174
if (col >= ColumnCount)
176
return ColumnData[col].Width;
178
/** Get all text for this item. This is used for copying, drag & drop and memo editing etc.
180
* @return All of the text.
182
virtual QString allText(int col) const
184
if (col >= ColumnCount)
185
return QString::null;
186
return ColumnData[col].Data;
188
/** Get the text to be displayed as tooltip for this item.
190
* @return The text to display as tooltip.
192
virtual QString tooltip(int col) const
198
/** This item expands the height to commodate all lines in the input buffer.
200
class toResultViewMLine : public toResultViewItem
203
/** Number of lines in the largest row.
207
virtual int realWidth(const QFontMetrics &fm, const QListView *top, int column, const QString &txt) const;
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
214
toResultViewMLine(QListView *parent, QListViewItem *after, const QString &buf = QString::null)
215
: toResultViewItem(parent, after, QString::null)
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
226
toResultViewMLine(QListViewItem *parent, QListViewItem *after, const QString &buf = QString::null)
227
: toResultViewItem(parent, after, QString::null)
233
/** Reimplemented for internal reasons.
235
virtual void setText (int, const QString &);
236
/** Set from database.
238
virtual void setText (int col, const toQValue &val);
239
/** Reimplemented for internal reasons.
241
virtual void setup(void);
242
/** Reimplemented for internal reasons.
244
virtual QString text(int col) const
246
return toResultViewItem::allText(col);
248
/** Reimplemented for internal reasons.
250
virtual void paintCell (QPainter *pnt, const QColorGroup & cg, int column, int width, int alignment);
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.
257
class toResultViewCheck : public QCheckListItem
265
enum { String, Number } Type;
270
virtual int realWidth(const QFontMetrics &fm, const QListView *top, int column, const QString &txt) const;
271
QString firstText(int col) const;
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.
278
toResultViewCheck(QListView *parent, const QString &text, QCheckListItem::Type type = Controller)
279
: QCheckListItem(parent, QString::null, type)
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.
291
toResultViewCheck(QListViewItem *parent, const QString &text, QCheckListItem::Type type = Controller)
292
: QCheckListItem(parent, QString::null, type)
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.
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.
312
toResultViewCheck(QListViewItem *parent, QListViewItem *after, const QString &text, QCheckListItem::Type type = Controller);
313
/** Reimplemented for internal reasons.
315
virtual ~toResultViewCheck()
319
/** Reimplemented for internal reasons.
321
virtual void setText (int col, const QString &txt);
322
/** Set from database.
324
virtual void setText (int col, const toQValue &val);
325
/** Reimplemented for internal reasons.
327
virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align);
328
/** Reimplemented for internal reasons.
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.
334
* @param asc Wether to sort ascending or not.
336
/** String to sort the data on. This is reimplemented so that numbers are sorted as numbers
337
* and not as strings.
339
* @param asc Wether to sort ascending or not.
341
virtual QString key(int col, bool asc) const
343
if (col >= ColumnCount)
344
return QString::null;
345
return asc ? ColumnData[col].KeyAsc : ColumnData[col].KeyDesc;
347
/** Reimplemented for internal reasons.
349
virtual int width(const QFontMetrics &, const QListView *, int col) const
351
if (col >= ColumnCount)
353
return ColumnData[col].Width;
355
/** Get all text for this item. This is used for copying, drag & drop and memo editing etc.
357
* @return All of the text.
359
virtual QString allText(int col) const
361
if (col >= ColumnCount)
362
return QString::null;
363
return ColumnData[col].Data;
365
/** Get the text to be displayed as tooltip for this item.
367
* @return The text to display as tooltip.
369
virtual QString tooltip(int col) const
375
/** This item expands the height to commodate all lines in the input buffer.
377
class toResultViewMLCheck : public toResultViewCheck
380
/** Number of lines in the largest row.
384
virtual int realWidth(const QFontMetrics &fm, const QListView *top, int column, const QString &txt) const;
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.
391
toResultViewMLCheck(QListView *parent, const QString &text, QCheckListItem::Type type = Controller)
392
: toResultViewCheck(parent, QString::null, type)
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.
403
toResultViewMLCheck(QListViewItem *parent, const QString &text, QCheckListItem::Type type = Controller)
404
: toResultViewCheck(parent, QString::null, type)
410
/** Reimplemented for internal reasons.
412
virtual void setup(void);
413
/** Reimplemented for internal reasons.
415
virtual void setText (int, const QString &);
416
/** Set from database.
418
virtual void setText (int col, const toQValue &val);
419
/** Reimplemented for internal reasons.
421
virtual QString text(int col) const
423
return toResultViewCheck::allText(col);
425
/** Reimplemented for internal reasons.
427
virtual void paintCell (QPainter *pnt, const QColorGroup & cg, int column, int width, int alignment);
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.
436
class toListView : public QListView, public toEditWidget
442
/** Name of this list, used primarily when printing. Also used to be able to edit
443
* SQL displayed in @ref toResultView.
446
/** Used to display tip on fields.
449
/** Item selected when popup menu displayed.
451
QListViewItem *MenuItem;
452
/** Column of item selected when popup menu displayed.
455
/** Popup menu if available.
458
/** Last move, used to determine if drag has started.
462
/** Reimplemented for internal reasons.
464
virtual void contentsMouseDoubleClickEvent (QMouseEvent *e);
465
/** Reimplemented for internal reasons.
467
virtual void contentsMousePressEvent(QMouseEvent *e);
468
/** Reimplemented for internal reasons.
470
virtual void contentsMouseReleaseEvent(QMouseEvent *e);
471
/** Reimplemented for internal reasons.
473
virtual void contentsMouseMoveEvent (QMouseEvent *e);
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).
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);
498
bool getIncludeHeader(){return includeHeader;};
499
bool getOnlySelection(){return onlySelection;};
500
QString getSep(){return sep;};
501
QString getDel(){return del;};
503
/** Create new list view.
504
* @param parent Parent of list.
505
* @param name Name of list.
506
* @param f Widget flags.
508
toListView(QWidget *parent, const char *name = NULL, WFlags f = 0);
509
virtual ~toListView();
511
/** Get SQL name of list.
513
virtual QString sqlName(void)
517
/** Set SQL name of list.
519
virtual void setSQLName(const QString &name)
525
* introduced to get type information for fields
527
virtual void setOwner(QString const & tOwner)
534
* introduced to get type information for fields
536
virtual void setObjectName(QString const & tObjectName)
538
objectName = tObjectName;
542
* introduced to get type information for fields
544
virtual QString getOwner()
551
* introduced to get type information for fields
553
virtual QString getObjectName()
558
/** Get the whole text for the item and column selected when menu was poped up.
560
QString menuText(void);
564
virtual void editPrint(void);
565
/** Reimplemented for internal reasons.
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.
571
virtual QString middleString()
573
return QString::null;
575
/** Adds option to add menues to the popup menu before it is displayed.
576
* @param menu Menu to add entries to.
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.
586
virtual QString exportAsText(bool includeHeader, bool onlySelection, int type = -1, const QString &separator = ";", const QString &delimiter = "\"");
587
/** Export list as file.
589
virtual bool editSave(bool ask);
591
/** Select all contents.
593
virtual void editSelectAll(void)
598
/** Move to top of data
600
virtual void searchTop(void)
603
setCurrentItem(firstChild());
606
/** Search for next entry
607
* @return True if found, should select the found text.
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.
613
virtual bool searchCanReplace(bool all);
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.
619
virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix);
621
* @param data Data to read from a map.
622
* @param prefix Prefix to read data from.
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.
628
virtual toListView *copyTransposed(void);
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.
633
void displayMenu(QPopupMenu *menu);
635
/** set the popup menu --> see displayMenu()
636
* @param item Item to display.
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.
644
virtual void displayMenu(QListViewItem *item, const QPoint &pnt, int col);
645
/** Display memo of selected menu column
647
virtual void displayMemo(void);
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.
653
virtual void menuCallback(int id);
657
* This class defines a list which displays the result of a query.
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.
663
class toResultView : public toListView, public toResult
671
/** Reimplemented for internal reasons.
673
virtual void keyPressEvent (QKeyEvent * e);
675
/** Connection to execute statement on.
680
QListViewItem *LastItem;
682
/** Number of rows in list.
685
/** If column names are to be made more readable.
687
bool ReadableColumns;
688
/** Wether to display first number column or not.
691
/** If all the available data should be read at once.
694
/** Input filter if any.
696
toResultFilter *Filter;
699
* @param readable Wether to display first number column or not.
700
* @param dispCol Wether to display first number column or not.
702
void setup(bool readable, bool dispCol);
704
/** Check if end of query is detected yet or not.
706
virtual bool eof(void);
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.
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.
723
toResultView(QWidget *parent, const char *name = NULL, WFlags f = 0);
726
/** Set the read all flag.
727
* @param all New value of flag.
729
void setReadAll(bool all)
734
/** Get read all flag
735
* @return Value of read all flag.
737
virtual void editReadAll(void);
739
/** Get the number of columns in query.
740
* @return Columns in query.
742
int queryColumns() const;
744
/** Get the query used to execute this.
751
/** Set a filter to this list.
752
* @param filter The new filter or NULL if no filter is to be used.
754
void setFilter(toResultFilter *filter)
758
/** Get the current filter.
759
* @return Current filter or NULL if no filter.
761
toResultFilter *filter(void)
766
/** Get number column flag.
767
* @return Wether or not the numbercolumn is displayed.
769
bool numberColumn() const
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.
778
void setNumberColumn(bool val)
783
/** Get readable column flag.
784
* @return Wether or not the readable column names.
786
bool readableColumn() const
788
return ReadableColumns;
790
/** Set readable column flag.
792
void setReadableColumns(bool val)
794
ReadableColumns = val;
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.
803
virtual QListViewItem *createItem(QListViewItem *last, const QString &str);
805
/** Reimplemented for internal reasons.
807
virtual void query(const QString &sql, const toQList ¶m);
809
/** Get SQL name of list.
811
virtual QString sqlName(void)
813
return toListView::sqlName();
815
/** Set SQL name of list.
817
virtual void setSQLName(const QString &name)
819
toListView::setSQLName(name);
822
// Why are these needed?
824
/** Set the SQL statement of this list
825
* @param sql String containing statement.
827
void setSQL(const QString &sql)
829
toResult::setSQL(sql);
831
/** Set the SQL statement of this list. This will also affect @ref Name.
832
* @param sql SQL containing statement.
834
void setSQL(const toSQL &sql)
836
toResult::setSQL(sql);
838
/** Set new SQL and run query.
839
* @param sql New sql.
842
void query(const QString &sql)
844
toResult::query(sql);
846
/** Set new SQL and run query.
847
* @param sql New sql.
850
void query(const toSQL &sql)
852
toResult::query(sql);
854
/** Set new SQL and run query.
855
* @param sql New sql.
858
void query(const toSQL &sql, toQList &par)
860
toResult::query(sql, par);
864
/** Reimplemented for internal reasons.
866
virtual void editPrint(void)
869
toListView::editPrint();
871
/** Reimplemented for internal reasons.
873
virtual QString middleString();
875
/** Reimplemented for internal reasons.
877
virtual void addMenues(QPopupMenu *);
878
/** Reimplemented for internal reasons.
880
virtual void setSorting(int col, bool asc = true);
881
/** Reimplemented for internal reasons.
883
virtual int sortColumn() const
888
/** Reimplemented for internal reasons.
890
virtual void refresh(void);
891
/** Reimplemented for internal reasons.
893
virtual void changeParams(const QString &Param1)
895
toResult::changeParams(Param1);
897
/** Reimplemented For internal reasons.
899
virtual void changeParams(const QString &Param1, const QString &Param2)
901
toResult::changeParams(Param1, Param2);
903
/** Reimplemented for internal reasons.
905
virtual void changeParams(const QString &Param1, const QString &Param2, const QString &Param3)
907
toResult::changeParams(Param1, Param2, Param3);
909
/** Try to add an item to the list if available.
911
virtual void addItem(void);
912
/** Handle any connection by default
914
virtual bool canHandle(toConnection &)
919
void headingClicked(int col);
920
void checkHeading(void);
922
/** Reimplemented for internal reasons.
924
virtual void menuCallback(int);
928
* Used internally by toListView.
932
class toResultListFormat : public toResultListFormatUI
936
toResultListFormat(QWidget *parent, const char *name);
937
void saveDefault(void);
939
virtual void formatChanged(int pos);