From: <mrj...@us...> - 2008-01-08 23:15:50
|
Revision: 2413 http://tora.svn.sourceforge.net/tora/?rev=2413&view=rev Author: mrjohnson0 Date: 2008-01-08 15:15:27 -0800 (Tue, 08 Jan 2008) Log Message: ----------- new classes using qt's new mvc architecture. uses toResult and is generally a sed replacement for toresultlong. Added Paths: ----------- branches/tora-1.4/tora/src/toresultmodel.cpp branches/tora-1.4/tora/src/toresultmodel.h branches/tora-1.4/tora/src/toresulttableview.cpp branches/tora-1.4/tora/src/toresulttableview.h Added: branches/tora-1.4/tora/src/toresultmodel.cpp =================================================================== --- branches/tora-1.4/tora/src/toresultmodel.cpp (rev 0) +++ branches/tora-1.4/tora/src/toresultmodel.cpp 2008-01-08 23:15:27 UTC (rev 2413) @@ -0,0 +1,378 @@ +/***** +* +* 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. +* +*****/ + +#include "config.h" +#include "toresultmodel.h" +#include "toconf.h" +#include "utils.h" +#include "toconfiguration.h" +#include "toqvalue.h" + + +#define TO_POLL_CHECK 100 + + +toResultModel::toResultModel(toNoBlockQuery *query, + QObject *parent, + bool edit, + bool read, + bool num) + : QAbstractTableModel(parent) { + ReadableColumns = read; + NumberColumn = num; + HeadersRead = false; + First = true; + Editable = edit; + + CurrentRow = 0; + + Query = QPointer<toNoBlockQuery>(query); + Query->setParent(this); + + connect(&Timer, SIGNAL(timeout(void)), this, SLOT(readData(void))); + Timer.start(TO_POLL_CHECK); +} + + +toResultModel::~toResultModel() { + if(Query) + delete Query; + Query = NULL; +} + + +void toResultModel::cleanup() { + if(Query) { + delete Query; + Timer.stop(); + + emit done(); + } + + Query = NULL; +} + + +void toResultModel::readData() { + if(!Query) { + cleanup(); + return; + } + + int MaxNumber = toConfigurationSingle::Instance().globalConfig( + CONF_MAX_NUMBER, DEFAULT_MAX_NUMBER).toInt(); + MaxNumber += CurrentRow; + + try { + if(!Query->poll()) { + if(!Timer.isActive()) + Timer.start(TO_POLL_CHECK); + return; + } + + readHeaders(); + + int cols = Headers.size(); + + if(!Query->eof()) { + do { + Row row; + + for(int j = 0; (j < cols || j == 0) && !Query->eof(); j++) + row.append(Query->readValueNull()); + + Rows.append(row); + CurrentRow++; + } + while(!Query->eof() && Query->poll() && + (MaxNumber < 0 || MaxNumber > CurrentRow)); + } + + // not really first, but just be sure to emit before done() + if(First) { + First = !First; + emit firstResult(Query->sql(), + tr("Statement executed"), // todo + false); + } + + if(Query->eof()) { + cleanup(); + reset(); + return; + } + } + catch(const toConnection::exception &str) { + if(First) { + First = !First; + emit firstResult( + Query != NULL ? Query->sql() : (const QString) NULL, + str, + true); + } + cleanup(); + return; + } + catch(const QString &str) { + if(First) { + First = !First; + emit firstResult( + Query != NULL ? Query->sql() : (const QString) NULL, + str, + true); + } + cleanup(); + return; + } + + // reset timer if needed + if(MaxNumber < 0 || MaxNumber > CurrentRow) + Timer.start(TO_POLL_CHECK); + else + Timer.stop(); + + // redraw view to apply changes + reset(); +} + + + +/** + * Returns the number of rows under the given parent. When the + * parent is valid it means that rowCount is returning the + * number of children of parent. + * + * Tip: When implementing a table based model, rowCount() + * should return 0 when the parent is valid. + */ +int toResultModel::rowCount(const QModelIndex &parent) const { + if(parent.isValid()) + return 0; + + return CurrentRow; +} + + +/** + * Returns the data stored under the given role for the item + * referred to by the index. + */ +QVariant toResultModel::data(const QModelIndex &index, int role) const { + if(!index.isValid()) + return QVariant(); + + if(index.row() > Rows.size() - 1 || index.column() > Headers.size() - 1) + return QVariant(); + + toQValue data = Rows.at(index.row()).at(index.column()); + + if(role == Qt::DisplayRole) { + if(data.isNull()) + return toNull(data).toQVariant(); + if(data.isString()) { + QString s = data.toString(); + if(s.length() > 33) // todo, get width of column + return s.left(33) + "..."; + } + + return data.toQVariant(); + } + if(role == Qt::EditRole) + return data.toQVariant(); + if(role == Qt::ToolTipRole) + return data.toQVariant(); + if(role == Qt::BackgroundRole) { + if(data.isNull()) + return QVariant(QColor("#f2ffbc")); + return QVariant(); + } + if(role == Qt::TextAlignmentRole) + return Headers.at(index.column()).align; + + return QVariant(); +} + + +/** + * Returns the data for the given role and section in the header + * with the specified orientation. + * + */ +QVariant toResultModel::headerData(int section, + Qt::Orientation orientation, + int role) const { + if(role != Qt::DisplayRole) + return QVariant(); + + if(orientation == Qt::Horizontal) { + if(!HeadersRead) + return QVariant(); + + if(section > Headers.size() - 1) + return QVariant(); + + return Headers[section].name; + } + + if(NumberColumn && orientation == Qt::Vertical) + return section + 1; + + return QVariant(); +} + + + +void toResultModel::readHeaders() { + if(HeadersRead) + return; + + toQDescList desc = Query->describe(); + for(toQDescList::iterator i = desc.begin(); i != desc.end(); i++) { + struct HeaderDesc d; + + d.name = (*i).Name; + if(ReadableColumns) + toReadableColumn(d.name); + + d.datatype = (*i).Datatype; + + d.nullAllowed = (*i).Null; + + if((*i).AlignRight) + d.align = Qt::AlignRight; + else + d.align = Qt::AlignLeft; + + Headers.append(d); + } + + HeadersRead = true; +} + + +/** + * Returns the number of columns for the children of the given + * parent. When the parent is valid it means that rowCount is + * returning the number of children of parent. + */ +int toResultModel::columnCount(const QModelIndex &parent) const { + return Headers.size(); +} + + +bool toResultModel::canFetchMore(const QModelIndex &parent) const { + try { + return Query && Query->poll(); + } + catch(...) { + // will catch later + ; + } + + return false; +} + + +void toResultModel::fetchMore(const QModelIndex &parent) { + readData(); +} + + +Qt::ItemFlags toResultModel::flags(const QModelIndex &index) const { + Qt::ItemFlags fl = Qt::ItemIsEnabled | Qt::ItemIsSelectable; + if(Editable) + fl = fl | Qt::ItemIsEditable; + return fl; +} + + +void toResultModel::setAlignment(int col, Qt::AlignmentFlag fl) { + Headers[col].align = fl; +} + + +int toResultModel::partition(int left, + int right, + int pivot, + int column, + Qt::SortOrder order) { + Rows.move(pivot, right); // move to end + + int store = left; + toQValue key = Rows.at(right).at(column); // pivot value for + // comparisons + + for(int i = left; i < right; i++) { + if(order == Qt::AscendingOrder && (Rows.at(i).at(column) < key) || + order == Qt::DescendingOrder && (Rows.at(i).at(column) > key)) + Rows.swap(i, store++); + } + + Rows.swap(store, right); + return store; +} + + +void toResultModel::qsort(int left, + int right, + int column, + Qt::SortOrder order) { + // quick sort + + // mrj: i'm not an algorithm guy and i don't really want to do + // this, but there's no good way to do this within qt. + + // i did a quick 'n dirty implementation following + // http://en.wikipedia.org/wiki/Quicksort + + if(right <= left) + return; + + int pivotIndex = left; + int index = partition(left, right, pivotIndex, column, order); + qsort(left, index - 1, column, order); + qsort(index + 1, right, column, order); +} + + +void toResultModel::sort(int column, Qt::SortOrder order) { + if(column > Headers.size() - 1) + return; + + qsort(0, Rows.size() - 1, column, order); + reset(); +} Added: branches/tora-1.4/tora/src/toresultmodel.h =================================================================== --- branches/tora-1.4/tora/src/toresultmodel.h (rev 0) +++ branches/tora-1.4/tora/src/toresultmodel.h 2008-01-08 23:15:27 UTC (rev 2413) @@ -0,0 +1,240 @@ +/***** +* +* 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 TORESULTMODEL_H +#define TORESULTMODEL_H + +#include "config.h" +#include "tosql.h" +#include "toresult.h" +#include "toconnection.h" +#include "tonoblockquery.h" +#include "tobackground.h" + +#include <QObject> +#include <QAbstractTableModel> +#include <QModelIndex> +#include <QList> +#include <QMap> + +class toQValue; + + +class toResultModel : public QAbstractTableModel { + Q_OBJECT; + +private: + QPointer<toNoBlockQuery> Query; + + typedef QList<toQValue> Row; + typedef QList<Row> RowList; + RowList Rows; + + int CurrentRow; + + // Timer to poll for new data. + toBackground Timer; + + // If column names are to be made more readable. + bool ReadableColumns; + + // display first number column or not. + bool NumberColumn; + + // when to emit firstResult + bool First; + + // return editable flag + bool Editable; + + struct HeaderDesc { + QString name; /* column name */ + QString datatype; /* data type from queryDescribe */ + bool nullAllowed; /* data can be null */ + Qt::AlignmentFlag align; /* alignment */ + }; + + typedef QList<HeaderDesc> HeaderList; + HeaderList Headers; + + // headers read already? + bool HeadersRead; + + // reads and sets up Headers + void readHeaders(void); + + // destroys query, stops timer, good things. + // emits done() + void cleanup(void); + + // helpers for sort implementation + int partition(int, int, int, int, Qt::SortOrder); + void qsort(int, int, int, Qt::SortOrder); + + +public: + toResultModel(toNoBlockQuery *query, + QObject *parent = 0, + bool edit = false, + bool read = false, + bool num = true); + + ~toResultModel(); + + + // ------------------------------ overrides ItemModel parent + + /** + * Returns the number of rows under the given parent. When the + * parent is valid it means that rowCount is returning the + * number of children of parent. + * + * Tip: When implementing a table based model, rowCount() + * should return 0 when the parent is valid. + */ + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + + /** + * Returns the data stored under the given role for the item + * referred to by the index. + */ + virtual QVariant data(const QModelIndex &index, int role) const; + + + /** + * Returns the data for the given role and section in the header + * with the specified orientation. + * + */ + QVariant headerData(int section, + Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + + /** + * Returns the number of columns for the children of the given + * parent. When the parent is valid it means that rowCount is + * returning the number of children of parent. + */ + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + + /** + * Returns true if there is more data available for parent, + * otherwise false. + * + */ + virtual bool canFetchMore(const QModelIndex &parent) const; + + + /** + * Fetches any available data for the items with the parent + * specified by the parent index. + * + */ + virtual void fetchMore(const QModelIndex &parent); + + + /** + * Returns the item flags for the given index. + * + */ + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + + + /** + * Set the column alignment for given column + * + */ + virtual void setAlignment(int col, Qt::AlignmentFlag fl); + + + /** + * Sorts the model by column in the given order. + * + */ + virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); + + + /** + * override parent to make public + * + */ + QModelIndex createIndex(int row, int column, void *ptr = 0) const { + return QAbstractTableModel::createIndex(row, column, ptr); + } + + + /** + * stop running query + * + */ + void stop(void) { + cleanup(); + } + +signals: + + /** + * Emitted when query is finnished. + * + */ + void done(void); + + + /** + * Emitted when the first result is available. + * + * @param sql SQL that was run. + * @param res String describing result. + * @param error Error has occurred. + */ + void firstResult(const QString &sql, + const toConnection::exception &res, + bool error); + + +public slots: + + /** + * reads ands sets up Rows and Columns + * + */ + void readData(void); +}; + + +#endif Added: branches/tora-1.4/tora/src/toresulttableview.cpp =================================================================== --- branches/tora-1.4/tora/src/toresulttableview.cpp (rev 0) +++ branches/tora-1.4/tora/src/toresulttableview.cpp 2008-01-08 23:15:27 UTC (rev 2413) @@ -0,0 +1,244 @@ +/***** +* +* 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. +* +*****/ + +#include "config.h" +#include "toresulttableview.h" +#include "toresultmodel.h" +#include "toconf.h" +#include "utils.h" +#include "toconfiguration.h" +#include "toconnection.h" +#include "tomemoeditor.h" +#include "tomain.h" + +#include <QClipboard> + + +toResultTableView::toResultTableView(QWidget *parent, bool editable) + : QTableView(parent), toResult() { + setHandle(true); + + Statistics = NULL; + Menu = NULL; + Model = NULL; + Editable = editable; + ReadAll = false; + + createActions(); + + setSelectionBehavior(QAbstractItemView::SelectRows); + setSelectionMode(QAbstractItemView::SingleSelection); + + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, + SIGNAL(customContextMenuRequested(const QPoint &)), + this, + SLOT(displayMenu(const QPoint &))); +} + + +toResultTableView::~toResultTableView() { + if(Model) + delete Model; + Model = NULL; +} + + +void toResultTableView::query(const QString &sql, const toQList ¶m) { + if(!setSQLParams(sql, param)) + throw tr("toResultTableView: Error calling setSQLParams"); + + toNoBlockQuery *query = NULL; + try { + query = new toNoBlockQuery(connection(), + toQuery::Long, + sql, + param, + Statistics); + query->eof(); // checks for error and throws + + Model = new toResultModel(query, this, Editable); + setModel(Model); + + connect(Model, SIGNAL(done()), this, SLOT(handleDone())); + connect(Model, SIGNAL(modelReset()), this, SLOT(handleReset())); + connect(Model, + SIGNAL(firstResult(const QString &, + const toConnection::exception &, + bool)), + this, + SLOT(handleFirst(const QString &, + const toConnection::exception &, + bool))); + + setSortingEnabled(true); + } + catch(const toConnection::exception &str) { + emit firstResult(toResult::sql(), str, true); + emit done(); + } + catch(const QString &str) { + emit firstResult(toResult::sql(), str, true); + emit done(); + } +} + + +void toResultTableView::createActions() { + displayAct = new QAction(tr("&Display in editor..."), this); + leftAct = new QAction(tr("&Left"), this); + centerAct = new QAction(tr("&Center"), this); + rightAct = new QAction(tr("&Right"), this); + copyAct = new QAction(tr("&Copy field"), this); + copySelAct = new QAction(tr("Copy &selection"), this); + copyHeadAct = new QAction(tr("Copy selection with &header"), this); + copyTransAct = new QAction(tr("Copy &transposed"), this); + selectAllAct = new QAction(tr("Select &all"), this); + exportAct = new QAction(tr("E&xport to file..."), this); + editAct = new QAction(tr("&Edit SQL..."), this); + readAllAct = new QAction(tr("&Read All"), this); +} + + +void toResultTableView::displayMenu(const QPoint &pos) { + if(!Menu) { + Menu = new QMenu(this); + Menu->addAction(displayAct); + + QMenu *just = new QMenu(tr("A&lignment"), this); + just->addAction(leftAct); + just->addAction(centerAct); + just->addAction(rightAct); + connect(just, + SIGNAL(triggered(QAction *)), + this, + SLOT(menuCallback(QAction *))); + Menu->addAction(just->menuAction()); + + Menu->addSeparator(); + + Menu->addAction(copyAct); + Menu->addAction(copySelAct); + Menu->addAction(copyHeadAct); + Menu->addAction(copyTransAct); + + Menu->addSeparator(); + + Menu->addAction(selectAllAct); + + Menu->addSeparator(); + + Menu->addAction(exportAct); + + Menu->addSeparator(); + + Menu->addAction(editAct); + + Menu->addSeparator(); + + Menu->addAction(readAllAct); + + connect(Menu, + SIGNAL(triggered(QAction *)), + this, + SLOT(menuCallback(QAction *))); + + emit displayMenu(Menu); + } + + Menu->exec(QCursor::pos()); +} + + +void toResultTableView::menuCallback(QAction *action) { + QModelIndex index = currentIndex(); + QVariant data = model()->data(index, Qt::EditRole); + + if(action == displayAct) { + toMemoEditor *ed = new toMemoEditor(this, data.toString()); + ed->exec(); + } + else if(action == leftAct) + Model->setAlignment(index.column(), Qt::AlignLeft); + else if(action == rightAct) + Model->setAlignment(index.column(), Qt::AlignRight); + else if(action == centerAct) + Model->setAlignment(index.column(), Qt::AlignHCenter); + else if(action == copyAct) { + QClipboard *clip = qApp->clipboard(); + + if(data.canConvert<QString>()) + clip->setText(data.toString()); + } + else if(action == selectAllAct) { + selectAll(); + } + else if(action == editAct) { + toMainWidget()->editSQL(sqlName()); + } + else if(action == readAllAct) { + QModelIndex index; + while(Model->canFetchMore(index)) + Model->fetchMore(index); + } + else + toStatusMessage(tr("Not implemented.")); +} + + +void toResultTableView::handleDone(void) { + if(ReadAll) { + QModelIndex index; + while(Model->canFetchMore(index)) + Model->fetchMore(index); + } + else + readAllAct->setEnabled(false); + emit done(); +} + + +void toResultTableView::handleReset(void) { + resizeColumnsToContents(); +} + + +void toResultTableView::handleFirst(const QString &sql, + const toConnection::exception &res, + bool error) { + emit firstResult(sql, res, error); +} Added: branches/tora-1.4/tora/src/toresulttableview.h =================================================================== --- branches/tora-1.4/tora/src/toresulttableview.h (rev 0) +++ branches/tora-1.4/tora/src/toresulttableview.h 2008-01-08 23:15:27 UTC (rev 2413) @@ -0,0 +1,206 @@ +/***** +* +* 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 TORESULTTABLEVIEW_H +#define TORESULTTABLEVIEW_H + +#include "config.h" +#include "toqvalue.h" +#include "tosql.h" +#include "toresult.h" +#include "toconnection.h" +#include "toresultmodel.h" + +#include <QObject> +#include <QAbstractTableModel> +#include <QTableView> +#include <QModelIndex> +#include <QList> +#include <QHeaderView> +#include <QMenu> + +class toResultStats; + + +class toResultTableView : public QTableView, public toResult { + Q_OBJECT; + + // the header widget + QHeaderView *Header; + + // Widget to store query statistics to. + toResultStats *Statistics; + + // if edit delegate should be created + bool Editable; + + // if all records should be read + bool ReadAll; + + // pointer to model + toResultModel *Model; + + /** + * context menu items. may be null. + * + */ + QMenu *Menu; + QAction *displayAct; + QAction *leftAct; + QAction *rightAct; + QAction *centerAct; + QAction *copyAct; + QAction *copySelAct; + QAction *copyHeadAct; + QAction *copyTransAct; + QAction *selectAllAct; + QAction *exportAct; + QAction *editAct; + QAction *readAllAct; + + void createActions(void); + + +protected slots: + void displayMenu(const QPoint &pos); + void menuCallback(QAction *action); + void handleDone(void); + void handleReset(void); + void handleFirst(const QString &sql, + const toConnection::exception &res, + bool error); + +signals: + + /** + * Called before the menu is displayed so that you can add items + * to it before it is shown. + * + * @param menu Pointer to the menu about to be shown. + */ + virtual void displayMenu(QMenu *menu); + + +public: + + /** + * Creates a new tableview + * + */ + toResultTableView(QWidget *parent = 0, bool editable = false); + ~toResultTableView(void); + + /** + * Reimplemented to create query and new model. + * + */ + virtual void query(const QString &sql, const toQList ¶m); + + + /** + * Reimplemented to create query and new model. + * + */ + void query(const QString &sql) { + toQList p; + query(sql, p); + } + + + /** + * Set statistics widget. + * @param stats Statistics widget. + */ + void setStatistics(toResultStats *stats) { + Statistics = stats; + } + + + /** + * override parent to return toResultModel pointer. + * + */ + toResultModel* model(void) const { + return Model; + } + + + // ---------------------------------------- stubs + + void stop(void) { + if(Model) + Model->stop(); + } + + + void setNumberColumn(bool) { + return; + } + + + bool running(void) { + return false; + } + + + virtual bool canHandle(toConnection &) { + return true; + } + + +signals: + + /** + * Emitted when the first result is available. + * + * @param sql SQL that was run. + * @param res String describing result. + * @param error Error has occurred. + */ + void firstResult(const QString &sql, + const toConnection::exception &res, + bool error); + + + /** + * Emitted when query is finnished. + * + */ + void done(void); +}; + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |