From: <ibr...@us...> - 2012-10-31 15:53:01
|
Revision: 4529 http://tora.svn.sourceforge.net/tora/?rev=4529&view=rev Author: ibre5041 Date: 2012-10-31 15:52:50 +0000 (Wed, 31 Oct 2012) Log Message: ----------- Modified Paths: -------------- branches/tora3/src/CMakeLists.txt branches/tora3/src/result/tomvc.h branches/tora3/src/result/totableview.h branches/tora3/src/tools/tosandboxtool.cpp branches/tora3/src/tools/tosandboxtool.h Added Paths: ----------- branches/tora3/src/result/toproviderobserver.cpp branches/tora3/src/result/toproviderobserver.h branches/tora3/src/result/totableview.cpp Modified: branches/tora3/src/CMakeLists.txt =================================================================== --- branches/tora3/src/CMakeLists.txt 2012-10-29 14:54:55 UTC (rev 4528) +++ branches/tora3/src/CMakeLists.txt 2012-10-31 15:52:50 UTC (rev 4529) @@ -243,6 +243,9 @@ editor/tohighlightedtext.h editor/tosearchreplace.h + result/totableview.h + result/toproviderobserver.h + ts_log/toostream.h connection/toqmysqlsetting.h @@ -473,7 +476,10 @@ editor/tohighlightedtext.cpp editor/tohighlightedtexteditor.cpp editor/tosearchreplace.cpp - + + result/toproviderobserver.cpp + result/totableview.cpp + migratetool/sqldeveloper.cpp migratetool/squirrelsql.cpp migratetool/tora3.cpp Modified: branches/tora3/src/result/tomvc.h =================================================================== --- branches/tora3/src/result/tomvc.h 2012-10-29 14:54:55 UTC (rev 4528) +++ branches/tora3/src/result/tomvc.h 2012-10-31 15:52:50 UTC (rev 4529) @@ -48,74 +48,47 @@ #include "core/toconnection.h" #include "core/totablemodel.h" +#include "result/toproviderobserver.h" + #include <QtCore/QObject> +#include <QtGui/QHeaderView> -struct MVCTRAITS +/** toTableView traits */ +struct MVCViewTraits { - /* toEditWidget traits */ - enum { OpenEnabled = 0 }; - enum { SaveEnabled = 0 }; - enum { PrintEnabled = 0 }; - enum { UndoEnabled = 0 }; - enum { RedoEnabled = 0 }; - enum { CutEnabled = 0 }; - enum { CopyEnabled = 0 }; - enum { PasteEnabled = 0 }; - enum { SearchEnabled = 0 }; - enum { SelectAllEnabled = 0 }; - enum { SelectBlockEnabled = 0 }; - enum { ReadAllEnabled = 0 }; + enum RowNumberPolicy { + BuiltInRowNumber = 0, + TableRowNumber = 1, + NoRowNumber = 2 + }; - /* toTableView traits */ - enum { SelectionBehavior = QAbstractItemView::SelectItems }; - enum { SelectionMode = QAbstractItemView::NoSelection }; - enum { AlternatingRowColors = false }; - enum { ContextMenuPolicy = Qt::NoContextMenu }; - enum { ShowRowNumber = false }; + enum + { + SelectionBehavior = QAbstractItemView::SelectItems, + SelectionMode = QAbstractItemView::NoSelection, + AlternatingRowColorsEnabled = false, + ContextMenuPolicy = Qt::NoContextMenu, + ShowRowNumber = TableRowNumber + }; }; -template<typename Model, typename View, typename T = MVCTRAITS> +template< + typename Model, + typename View, + typename VT = MVCViewTraits + > class TOMVC - : public View - , public toEventQuery::Client - , public toResult - , public toEditWidget + : public toResult + , public toProviderObserver { public: - typedef T Traits; + typedef VT ViewTraits; TOMVC(QWidget *parent); - void setModel(Model *); void setQuery(toEventQuery *); + QWidget *widget(); /** - * @name toEventQuery::Client - * toEventQuery::Client interface implementation - */ - ///@{ - /** - * Emitted when header descriptions are available - */ - virtual void eqDescriptionAvailable(toEventQuery*); - - /** - * Emitted when data has been read. - * @param rows Number of rows to be read - */ - virtual void eqDataAvailable(toEventQuery*); - - /** - * Emitted with error string - */ - virtual void eqError(toEventQuery*, const toConnection::exception &); - - /** - * Emitted when done - */ - virtual void eqDone(toEventQuery*); - ///@} - - /** * @name toResult * toResult interface implementation */ @@ -131,246 +104,107 @@ ///@} /** - * @name toEditWidget - * toEditWidget interface implementation + * @name toProviderObserver + * toProviderObserver interface implementation */ ///@{ - virtual QString editText(); - virtual bool editOpen(const QString&); - virtual bool editSave(bool); - virtual bool searchNext(); - virtual void editCopy(); - virtual void editCut(); - virtual void editPaste(); - virtual void editPrint(); - virtual void editReadAll(); - virtual void editRedo(); - virtual void editSelectAll(); - virtual void editUndo(); - virtual void searchReplace(); + virtual void observeHeaders(toTableModel::HeaderList &h); + virtual void observeRow(toTableModel::Row &r); ///@} private: Model *m_model; - toEventQuery *m_eventQuery; + View *m_view; }; -template<typename Model, typename View, typename T> -TOMVC<Model, View, T>::TOMVC(QWidget *parent) - : View(parent) - , toEventQuery::Client() - , toResult() - , toEditWidget() - , m_model(NULL) - , m_eventQuery(NULL) +template< + typename Model, + typename View, + typename VT + > +TOMVC<Model, View, VT>::TOMVC(QWidget *parent) + : toResult() + , toProviderObserver(new Model(parent)) + , m_model(toProviderObserver::model()) + , m_view(new View(parent)) { - if( Traits::OpenEnabled ) toEditWidget::FlagSet.Open = true; - if( Traits::SaveEnabled ) toEditWidget::FlagSet.Save = true; - if( Traits::PrintEnabled ) toEditWidget::FlagSet.Print = true; - if( Traits::UndoEnabled ) toEditWidget::FlagSet.Undo = true; - if( Traits::RedoEnabled ) toEditWidget::FlagSet.Redo = true; - if( Traits::CutEnabled ) toEditWidget::FlagSet.Cut = true; - if( Traits::CopyEnabled ) toEditWidget::FlagSet.Copy = true; - if( Traits::PasteEnabled ) toEditWidget::FlagSet.Paste = true; - if( Traits::SearchEnabled ) toEditWidget::FlagSet.Search = true; - if( Traits::SelectAllEnabled ) toEditWidget::FlagSet.SelectAll = true; - if( Traits::SelectBlockEnabled ) toEditWidget::FlagSet.SelectBlock = true; - if( Traits::ReadAllEnabled ) toEditWidget::FlagSet.ReadAll = true; + m_view->setModel(m_model); - View::setSelectionBehavior( (QAbstractItemView::SelectionBehavior)Traits::SelectionBehavior); - View::setSelectionMode( (QAbstractItemView::SelectionMode)Traits::SelectionMode); - View::setAlternatingRowColors( Traits::AlternatingRowColors); - View::setContextMenuPolicy( (Qt::ContextMenuPolicy)Traits::ContextMenuPolicy); + m_view->setSelectionBehavior( (QAbstractItemView::SelectionBehavior) ViewTraits::SelectionBehavior); + m_view->setSelectionMode( (QAbstractItemView::SelectionMode) ViewTraits::SelectionMode); + m_view->setAlternatingRowColors( ViewTraits::AlternatingRowColorsEnabled); + m_view->setContextMenuPolicy( (Qt::ContextMenuPolicy) ViewTraits::ContextMenuPolicy); - if( Traits::ShowRowNumber == false ) hideColumn(0); else showColumn(0); + if( ViewTraits::ShowRowNumber != MVCViewTraits::BuiltInRowNumber ) m_view->verticalHeader()->hide(); } -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::setModel(Model *m) +template< + typename Model, + typename View, + typename VT + > +void TOMVC<Model, View, VT>::setQuery(toEventQuery *q) { - m_model = m; - View::setModel(m_model); + toProviderObserver::setQuery(q); } -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::setQuery(toEventQuery *q) +template< + typename Model, + typename View, + typename VT + > +QWidget* TOMVC<Model, View, VT>::widget() { - if( m_eventQuery != NULL) - { - delete m_eventQuery; - } - - m_eventQuery = q; - - connect(m_eventQuery, SIGNAL(descriptionAvailable(toEventQuery*)) - , this, SLOT(eqDescriptionAvailable(toEventQuery*))); - connect(m_eventQuery, SIGNAL(dataAvailable(toEventQuery*)) - , this, SLOT(eqDataAvailable(toEventQuery*))); - connect(m_eventQuery, SIGNAL(error(toEventQuery*, const toConnection::exception &)) - , this, SLOT(eqError(toEventQuery*, const toConnection::exception &))); - connect(m_eventQuery, SIGNAL(done(toEventQuery*)) - , this, SLOT(eqDone(toEventQuery*))); - m_eventQuery->start(); + return m_view; } -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::eqDescriptionAvailable(toEventQuery *e) +template< + typename Model, + typename View, + typename VT + > +void TOMVC<Model, View, VT>::query(const QString &,const toQueryParams &) { - if (!m_eventQuery) - { - Q_ASSERT_X(false, qPrintable(__QHERE__), " phantom data"); - } - - if (m_eventQuery != e) - { - Q_ASSERT_X(false, qPrintable(__QHERE__), " unknown data source"); - } - - toQColumnDescriptionList const& desc = m_eventQuery->describe(); - toTableModel::HeaderList h; - for (toQColumnDescriptionList::const_iterator i = desc.constBegin(); i != desc.constEnd(); i++) - { - struct toTableModel::HeaderDesc d; - - d.name = (*i).Name; - d.datatype = (*i).Datatype; - - h << d; - } - m_model->setHeaders(h); } -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::eqDataAvailable(toEventQuery *e) +template< + typename Model, + typename View, + typename VT + > +bool TOMVC<Model, View, VT>::canHandle(toConnection &) { - if (!m_eventQuery) - { - Q_ASSERT_X(false, qPrintable(__QHERE__), "phantom data"); - } - - if (m_eventQuery != e) - { - Q_ASSERT_X(false, qPrintable(__QHERE__), "unknown data source"); - } - - if (m_model->columnCount(QModelIndex()) <= 0) - { - Q_ASSERT_X(false, qPrintable(__QHERE__), "not described yet"); - } - - toTableModel::RowList rows; - int columns = m_model->columnCount(QModelIndex()); - while(e->hasMore()) - { - toTableModel::Row row; - for(int i=0; i < columns; i++) - { - row << e->readValue(); - } - rows << row; - row.clear(); - } - - m_model->appendRows(rows); - - // TODO: this line is for testing only - m_eventQuery->setFetchMode(toEventQuery::READ_ALL); -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::eqError(toEventQuery*, const toConnection::exception &e) -{ - throw e; -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::eqDone(toEventQuery*) -{ - bool retval = m_eventQuery->disconnect(this); - if(retval == false) - throw __QHERE__ + " disconnect failed"; - m_eventQuery->deleteLater(); - m_eventQuery = NULL; -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::query(const QString &,const toQueryParams &) -{ -} - -template<typename Model, typename View, typename T> -bool TOMVC<Model, View, T>::canHandle(toConnection &) -{ return true; } -template<typename Model, typename View, typename T> -QString TOMVC<Model, View, T>::editText() +template< + typename Model, + typename View, + typename VT + > +void TOMVC<Model, View, VT>::observeHeaders(toTableModel::HeaderList &h) { - return ""; -} + if( ViewTraits::ShowRowNumber == MVCViewTraits::TableRowNumber ) + { + struct toTableModel::HeaderDesc d; -template<typename Model, typename View, typename T> -bool TOMVC<Model, View, T>::editOpen(const QString&) -{ - return false; + d.name = QString::fromAscii("#"); + d.datatype = QString::fromAscii("RowNumber"); + h.prepend(d); + } } -template<typename Model, typename View, typename T> -bool TOMVC<Model, View, T>::editSave(bool) +template< + typename Model, + typename View, + typename VT + > +void TOMVC<Model, View, VT>::observeRow(toTableModel::Row &r) { - return false; + if( ViewTraits::ShowRowNumber == MVCViewTraits::TableRowNumber ) + { + r << m_rows.size() + model()->rowCount() + 1; + } } -template<typename Model, typename View, typename T> -bool TOMVC<Model, View, T>::searchNext() -{ - return false; -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::editCopy() -{ -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::editCut() -{ -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::editPaste() -{ -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::editPrint() -{ -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::editReadAll() -{ -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::editRedo() -{ -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::editSelectAll() -{ -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::editUndo() -{ -} - -template<typename Model, typename View, typename T> -void TOMVC<Model, View, T>::searchReplace() -{ -} - #endif Added: branches/tora3/src/result/toproviderobserver.cpp =================================================================== --- branches/tora3/src/result/toproviderobserver.cpp (rev 0) +++ branches/tora3/src/result/toproviderobserver.cpp 2012-10-31 15:52:50 UTC (rev 4529) @@ -0,0 +1,184 @@ + +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * TOra - An Oracle Toolkit for DBA's and developers + * + * Shared/mixed copyright is held throughout files in this product + * + * Portions Copyright (C) 2000-2001 Underscore AB + * Portions Copyright (C) 2003-2005 Quest Software, Inc. + * Portions Copyright (C) 2004-2009 Numerous 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. + * + * You may link this product with any GPL'd Qt library. + * + * All trademarks belong to their respective owners. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "result/toproviderobserver.h" +#include "core/utils.h" + +toProviderObserver::toProviderObserver(toTableModel *model) + : QObject() + , toEventQuery::Client() + , m_model(model) + , m_eventQuery(NULL) + , m_headers() + , m_rows() +{} + +toProviderObserver::~toProviderObserver() +{ + if(m_eventQuery && m_eventQuery->parent() == this) + delete m_eventQuery; + m_eventQuery = NULL; +} + +void toProviderObserver::setQuery(toEventQuery *query) +{ + bool retval; + + if( m_eventQuery != NULL && m_eventQuery->parent() == this) + { + delete m_eventQuery; + } + + m_eventQuery = query; + + retval = QObject::connect(m_eventQuery, SIGNAL(descriptionAvailable(toEventQuery*)) + , this, SLOT(eqDescriptionAvailable(toEventQuery*))); + retval = QObject::connect(m_eventQuery, SIGNAL(dataAvailable(toEventQuery*)) + , this, SLOT(eqDataAvailable(toEventQuery*))); + retval = QObject::connect(m_eventQuery, SIGNAL(error(toEventQuery*, const toConnection::exception &)) + , this, SLOT(eqError(toEventQuery*, const toConnection::exception &))); + retval = QObject::connect(m_eventQuery, SIGNAL(done(toEventQuery*)) + , this, SLOT(eqDone(toEventQuery*))); + m_eventQuery->start(); +} + +toTableModel* toProviderObserver::model() +{ + return m_model; +} + +void toProviderObserver::observeHeaders(toTableModel::HeaderList &h) +{} + +void toProviderObserver::observeRow(toTableModel::Row &r) +{} + +void toProviderObserver::observeData(const toTableModel::RowList &r) +{} + +void toProviderObserver::observeDone() +{} + +void toProviderObserver::observeError(const toConnection::exception &e) +{} + +void toProviderObserver::eqDescriptionAvailable(toEventQuery *e) +{ + if (!m_eventQuery) + { + Q_ASSERT_X(false, qPrintable(__QHERE__), " phantom data"); + } + + if (m_eventQuery != e) + { + Q_ASSERT_X(false, qPrintable(__QHERE__), " unknown data source"); + } + + toQColumnDescriptionList const& desc = m_eventQuery->describe(); + for (toQColumnDescriptionList::const_iterator i = desc.constBegin(); i != desc.constEnd(); i++) + { + struct toTableModel::HeaderDesc d; + + d.name = (*i).Name; + d.datatype = (*i).Datatype; + + m_headers << d; + } + + observeHeaders(m_headers); + m_model->setHeaders(m_headers); +} + +void toProviderObserver::eqDataAvailable(toEventQuery *e) +{ + try + { + if (!m_eventQuery) + { + Q_ASSERT_X(false, qPrintable(__QHERE__), "phantom data"); + } + + if (m_eventQuery != e) + { + Q_ASSERT_X(false, qPrintable(__QHERE__), "unknown data source"); + } + + if (m_headers.count() <= 0) + { + Q_ASSERT_X(false, qPrintable(__QHERE__), "not described yet"); + } + + int columns = e->columnCount(); + while(e->hasMore()) + { + toTableModel::Row row; + observeRow(row); + for(int i=0; i < columns; i++) + { + row << e->readValue(); + } + m_rows << row; + //row.clear(); + } + + observeData(m_rows); + m_model->appendRows(m_rows); + m_rows.clear(); + } + TOCATCH +} + +void toProviderObserver::eqDone(toEventQuery*) +{ + bool retval = m_eventQuery->disconnect(this); + if(retval == false) + throw __QHERE__ + " disconnect failed"; + m_eventQuery->deleteLater(); + m_eventQuery = NULL; + observeDone(); +} + +void toProviderObserver::eqError(toEventQuery*, const toConnection::exception &e) +{ + observeError(e); +} + + Added: branches/tora3/src/result/toproviderobserver.h =================================================================== --- branches/tora3/src/result/toproviderobserver.h (rev 0) +++ branches/tora3/src/result/toproviderobserver.h 2012-10-31 15:52:50 UTC (rev 4529) @@ -0,0 +1,101 @@ + +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * TOra - An Oracle Toolkit for DBA's and developers + * + * Shared/mixed copyright is held throughout files in this product + * + * Portions Copyright (C) 2000-2001 Underscore AB + * Portions Copyright (C) 2003-2005 Quest Software, Inc. + * Portions Copyright (C) 2004-2009 Numerous 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. + * + * You may link this product with any GPL'd Qt library. + * + * All trademarks belong to their respective owners. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef __TOPROVIDEROBSERVER_H__ +#define __TOPROVIDEROBSERVER_H__ + +#include "core/toeventquery.h" +#include "core/totablemodel.h" + +#include <QtCore/QObject> + +class toProviderObserver : public QObject, toEventQuery::Client +{ + Q_OBJECT; +public: + toProviderObserver(toTableModel *); + ~toProviderObserver(); + + void setQuery(toEventQuery*); + toTableModel* model(); +protected: + virtual void observeHeaders(toTableModel::HeaderList &h); + virtual void observeRow(toTableModel::Row &r); + virtual void observeData(const toTableModel::RowList &r); + virtual void observeDone(); + virtual void observeError(const toConnection::exception &e); + +private slots: + /** + * @name toEventQuery::Client + * toEventQuery::Client interface implementation + */ + ///@{ + /** + * Emitted when header descriptions are available + */ + virtual void eqDescriptionAvailable(toEventQuery*); + + /** + * Emitted when data has been read. + * @param rows Number of rows to be read + */ + virtual void eqDataAvailable(toEventQuery*); + + /** + * Emitted with error string + */ + virtual void eqError(toEventQuery*, const toConnection::exception &); + + /** + * Emitted when done + */ + virtual void eqDone(toEventQuery*); + ///@} +protected: + toTableModel::RowList m_rows; +private: + toTableModel *m_model; + toEventQuery *m_eventQuery; + toTableModel::HeaderList m_headers; +}; + +#endif Added: branches/tora3/src/result/totableview.cpp =================================================================== --- branches/tora3/src/result/totableview.cpp (rev 0) +++ branches/tora3/src/result/totableview.cpp 2012-10-31 15:52:50 UTC (rev 4529) @@ -0,0 +1,48 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * TOra - An Oracle Toolkit for DBA's and developers + * + * Shared/mixed copyright is held throughout files in this product + * + * Portions Copyright (C) 2000-2001 Underscore AB + * Portions Copyright (C) 2003-2005 Quest Software, Inc. + * Portions Copyright (C) 2004-2009 Numerous 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. + * + * You may link this product with any GPL'd Qt library. + * + * All trademarks belong to their respective owners. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "result/totableview.h" + +toTableViewPriv::toTableViewPriv(QWidget *parent) + : QTableView(parent) +{ + +} + Modified: branches/tora3/src/result/totableview.h =================================================================== --- branches/tora3/src/result/totableview.h 2012-10-29 14:54:55 UTC (rev 4528) +++ branches/tora3/src/result/totableview.h 2012-10-31 15:52:50 UTC (rev 4529) @@ -43,17 +43,33 @@ #include <QTableView> + +class toTableViewPriv : public QTableView +{ + Q_OBJECT; +public: + toTableViewPriv(QWidget *parent = 0); +}; + template<typename Traits> -class toTableView : public QTableView +class ToTableView : public toTableViewPriv { public: - toTableView(QWidget *parent); + ToTableView(QWidget *parent = 0); +private: + void setup(); }; template<typename Traits> -toTableView<Traits>::toTableView(QWidget *parent) - : QTableView(parent) +ToTableView<Traits>::ToTableView(QWidget *parent) + : toTableViewPriv(parent) { + setup(); } +template<typename Traits> +void ToTableView<Traits>::setup() +{ +} + #endif Modified: branches/tora3/src/tools/tosandboxtool.cpp =================================================================== --- branches/tora3/src/tools/tosandboxtool.cpp 2012-10-29 14:54:55 UTC (rev 4528) +++ branches/tora3/src/tools/tosandboxtool.cpp 2012-10-31 15:52:50 UTC (rev 4529) @@ -106,17 +106,9 @@ m_statement->setText(QString::fromAscii("select * from dba_objects")); layout()->addWidget(m_statement); -// Result = new toResultView(this); -// layout()->addWidget(Result); - m_tableModel = new toTableModel(this); - //m_tableView = new QTableView(this); - //m_tableView->setModel(m_tableModel); - //layout()->addWidget(m_tableView); + m_mvc = new SandboxMVC(this); + layout()->addWidget(m_mvc->widget()); - SandboxMVC *m = new SandboxMVC(this); - m->setModel(m_tableModel); - layout()->addWidget(m); - connect(m_statement, SIGNAL(returnPressed()), this, SLOT(execute())); } @@ -132,93 +124,8 @@ , toEventQuery::READ_FIRST); //toQList params=toParamGet::getParam(this,sql); - connect(m_eventQuery, SIGNAL(descriptionAvailable(toEventQuery*)) - , this, SLOT(eqDescriptionAvailable(toEventQuery*))); - connect(m_eventQuery, SIGNAL(dataAvailable(toEventQuery*)) - , this, SLOT(eqDataAvailable(toEventQuery*))); - connect(m_eventQuery, SIGNAL(error(toEventQuery*, const toConnection::exception &)) - , this, SLOT(eqError(toEventQuery*, const toConnection::exception &))); - connect(m_eventQuery, SIGNAL(done(toEventQuery*)) - , this, SLOT(eqDone(toEventQuery*))); - m_eventQuery->start(); + m_mvc->setQuery(m_eventQuery); + } TOCATCH } - -void toSandbox::eqDescriptionAvailable(toEventQuery *e) -{ - if (!m_eventQuery) - { - Q_ASSERT_X(false, (__HERE__).c_str(), "toSandbox::eqDescriptionAvailable - phantom data"); - } - - if (m_eventQuery != e) - { - Q_ASSERT_X(false, (__HERE__).c_str(), "toSandbox::eqDescriptionAvailable - unknown data source"); - } - - toQColumnDescriptionList const& desc = m_eventQuery->describe(); - toTableModel::HeaderList h; - for (toQColumnDescriptionList::const_iterator i = desc.constBegin(); i != desc.constEnd(); i++) - { - struct toTableModel::HeaderDesc d; - - d.name = (*i).Name; - d.datatype = (*i).Datatype; - - h << d; - } - m_tableModel->setHeaders(h); - -} - -void toSandbox::eqDataAvailable(toEventQuery *e) -{ - if (!m_eventQuery) - { - Q_ASSERT_X(false, (__HERE__).c_str(), "toSandbox::eqDataAvailable - phantom data"); - } - - if (m_eventQuery != e) - { - Q_ASSERT_X(false, (__HERE__).c_str(), "toSandbox::eqDataAvailable - unknown data source"); - } - - if (m_tableModel->columnCount(QModelIndex()) <= 0) - { - Q_ASSERT_X(false, (__HERE__).c_str(), "toSandbox::eqDataAvailable - not described yet"); - } - - toTableModel::RowList rows; - int columns = m_tableModel->columnCount(QModelIndex()); - while(e->hasMore()) - { - toTableModel::Row row; - for(int i=0; i < columns; i++) - { - row << e->readValue(); - } - rows << row; - row.clear(); - } - - m_tableModel->appendRows(rows); - - m_eventQuery->setFetchMode(toEventQuery::READ_ALL); - -} - -void toSandbox::eqError(toEventQuery*, const toConnection::exception &e) -{ - throw e; -} - -void toSandbox::eqDone(toEventQuery*) -{ - bool retval = m_eventQuery->disconnect(this); - if(retval == false) - throw QString::fromAscii("toSandbox::eqDone disconnect failed"); - m_eventQuery->deleteLater(); - m_eventQuery = NULL; -} - Modified: branches/tora3/src/tools/tosandboxtool.h =================================================================== --- branches/tora3/src/tools/tosandboxtool.h 2012-10-29 14:54:55 UTC (rev 4528) +++ branches/tora3/src/tools/tosandboxtool.h 2012-10-31 15:52:50 UTC (rev 4529) @@ -18,23 +18,30 @@ class QTableView; class toEventQuery; -struct SandboxTraits : public MVCTRAITS +struct SandboxViewTraits : public MVCViewTraits { - enum { CopyEnabled = 1 }; - - enum { AlternatingRowColors = true }; - enum { ShowRowNumber = true }; + enum { AlternatingRowColorsEnabled = true }; + enum { ShowRowNumber = TableRowNumber }; }; -class SandboxMVC : public TOMVC<toTableModel, toTableView<SandboxTraits>, SandboxTraits> +class SandboxMVC + : public TOMVC< + toTableModel, + ToTableView<SandboxViewTraits>, + SandboxViewTraits + > { Q_OBJECT; public: - typedef TOMVC<toTableModel, toTableView<SandboxTraits>, SandboxTraits> super; + typedef TOMVC<toTableModel, + ToTableView<SandboxViewTraits>, + SandboxViewTraits + > super; SandboxMVC(QWidget *parent) : super(parent) {}; + virtual ~SandboxMVC() {}; }; -class toSandbox : public toToolWidget, toEventQuery::Client +class toSandbox : public toToolWidget //, toEventQuery::Client { Q_OBJECT; @@ -44,32 +51,6 @@ virtual ~toSandbox() {}; virtual void slotWindowActivated(toToolWidget*){}; -protected slots: - // --- begin overloads from toEventQueryClient --- - - /** - * Emitted when header descriptions are available - */ - virtual void eqDescriptionAvailable(toEventQuery*); - - /** - * Emitted when data has been read. - * @param rows Number of rows to be read - */ - virtual void eqDataAvailable(toEventQuery*); - - /** - * Emitted with error string - */ - virtual void eqError(toEventQuery*, const toConnection::exception &); - - /** - * Emitted when done - */ - virtual void eqDone(toEventQuery*); - - // --- end overloads from toEventQueryClient --- - private slots: void execute(void); @@ -79,6 +60,7 @@ toTableModel *m_tableModel; QTableView *m_tableView; toEventQuery *m_eventQuery; + SandboxMVC *m_mvc; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |