Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76304 - sandbox/icl/libs/xplore/br1/sqlbrowser
From: afojgo_at_[hidden]
Date: 2012-01-04 09:55:45


Author: jofaber
Date: 2012-01-04 09:55:44 EST (Wed, 04 Jan 2012)
New Revision: 76304
URL: http://svn.boost.org/trac/boost/changeset/76304

Log:
Tree and table view on an Sql-model.
Binary files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/media1.db
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 84 +++++++++++++++++++++++----------------
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.h | 12 ++++
   sandbox/icl/libs/xplore/br1/sqlbrowser/browserwidget.ui | 9 ++-
   3 files changed, 65 insertions(+), 40 deletions(-)

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp 2012-01-04 09:55:44 EST (Wed, 04 Jan 2012)
@@ -51,8 +51,11 @@
 {
     setupUi(this);
 
- table->addAction(insertRowAction);
- table->addAction(deleteRowAction);
+ ext_table->addAction(insertRowAction);
+ ext_table->addAction(deleteRowAction);
+
+ ext_tree->addAction(insertRowAction);
+ ext_tree->addAction(deleteRowAction);
 
     if (QSqlDatabase::drivers().isEmpty())
         QMessageBox::information(this, tr("No database drivers found"),
@@ -69,17 +72,18 @@
 
 void Browser::exec()
 {
- QSqlQueryModel *model = new QSqlQueryModel(table);
+ QSqlQueryModel *model = new QSqlQueryModel(ext_table);
     model->setQuery(QSqlQuery(sqlEdit->toPlainText(), connectionWidget->currentDatabase()));
 
- table->setModel(model);
+ ext_table->setModel(model);
+ ext_tree->setModel(model);//JOFA
 
     //JOFA additions ----------------------------------------------------------
- table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
+ ext_table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
 
- table->setSortingEnabled(true);
- table->setAlternatingRowColors(true);
- table->resizeColumnsToContents();
+ ext_table->setSortingEnabled(true);
+ ext_table->setAlternatingRowColors(true);
+ ext_table->resizeColumnsToContents();
     //JOFA additions ----------------------------------------------------------
 
 
@@ -184,25 +188,37 @@
     }
 }
 
-void Browser::showTable(const QString &t)
+QSqlTableModel* Browser::showTable(const QString &t)
 {
- QSqlTableModel *model = new QSqlTableModel(table, connectionWidget->currentDatabase());
+ QSqlTableModel *model = new QSqlTableModel(ext_table, connectionWidget->currentDatabase());
     model->setEditStrategy(QSqlTableModel::OnRowChange);
     model->setTable(connectionWidget->currentDatabase().driver()->escapeIdentifier(t, QSqlDriver::TableName));
     model->select();
     if (model->lastError().type() != QSqlError::NoError)
         emit statusMessage(model->lastError().text());
- table->setModel(model);
- table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
+ ext_table->setModel(model);
+ ext_table->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
 
     //JOFA additions ----------------------------------------------------------
- table->setSortingEnabled(true);
- table->setAlternatingRowColors(true);
- table->resizeColumnsToContents();
+ ext_table->setSortingEnabled(true);
+ ext_table->setAlternatingRowColors(true);
+ ext_table->resizeColumnsToContents();
     //JOFA additions ----------------------------------------------------------
 
     //REV connect(table->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged()));
- connect(table->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(on_rowSelectChanged()));
+ connect(ext_table->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(on_rowSelectChanged()));
+
+ updateActions();
+ return model;
+}
+
+void Browser::showTree(QSqlTableModel *model)
+{
+ ext_tree->setModel(model);
+ //JODO? ext_tree->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed);
+
+ //REV connect(table->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged()));
+ connect(ext_tree->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(on_rowSelectChanged()));
 
     updateActions();
 }
@@ -210,7 +226,7 @@
 void Browser::showMetaData(const QString &t)
 {
     QSqlRecord rec = connectionWidget->currentDatabase().record(t);
- QStandardItemModel *model = new QStandardItemModel(table);
+ QStandardItemModel *model = new QStandardItemModel(ext_table);
 
     model->insertRows(0, rec.count());
     model->insertColumns(0, 7);
@@ -238,35 +254,35 @@
         model->setData(model->index(i, 6), fld.defaultValue());
     }
 
- table->setModel(model);
- table->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ ext_table->setModel(model);
+ ext_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
 
     updateActions();
 }
 
 void Browser::insertRow()
 {
- QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model());
+ QSqlTableModel *model = qobject_cast<QSqlTableModel *>(ext_table->model());
     if (!model)
         return;
 
- QModelIndex insertIndex = table->currentIndex();
+ QModelIndex insertIndex = ext_table->currentIndex();
     int row = insertIndex.row() == -1 ? 0 : insertIndex.row();
     model->insertRow(row);
     insertIndex = model->index(row, 0);
- table->setCurrentIndex(insertIndex);
- table->edit(insertIndex);
+ ext_table->setCurrentIndex(insertIndex);
+ ext_table->edit(insertIndex);
 }
 
 void Browser::deleteRow()
 {
- QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model());
+ QSqlTableModel *model = qobject_cast<QSqlTableModel *>(ext_table->model());
     if (!model)
         return;
 
     model->setEditStrategy(QSqlTableModel::OnManualSubmit);
 
- QModelIndexList currentSelection = table->selectionModel()->selectedIndexes();
+ QModelIndexList currentSelection = ext_table->selectionModel()->selectedIndexes();
     for (int i = 0; i < currentSelection.count(); ++i) {
         if (currentSelection.at(i).column() != 0)
             continue;
@@ -282,8 +298,8 @@
 void Browser::updateActions()
 {
     //CL emit statusMessage(tr("updateActions()"));
- bool enableIns = qobject_cast<QSqlTableModel *>(table->model());
- bool enableDel = enableIns && table->currentIndex().isValid();
+ bool enableIns = qobject_cast<QSqlTableModel *>(ext_table->model());
+ bool enableDel = enableIns && ext_table->currentIndex().isValid();
 
     insertRowAction->setEnabled(enableIns);
     deleteRowAction->setEnabled(enableDel);
@@ -308,18 +324,18 @@
 
 void Browser::deselectFirstCell(int selectedRow)
 {
- QSqlTableModel *model = qobject_cast<QSqlTableModel *>(table->model());
+ QSqlTableModel *model = qobject_cast<QSqlTableModel *>(ext_table->model());
     QModelIndex firstCell;
     const int firstCol = 0;
     firstCell = model->index(selectedRow, firstCol, QModelIndex());
     QItemSelection toggleSelection;
     toggleSelection.select(firstCell, firstCell);
- table->selectionModel()->select(toggleSelection, QItemSelectionModel::Toggle);
+ ext_table->selectionModel()->select(toggleSelection, QItemSelectionModel::Toggle);
 }
 
 void Browser::on_rowSelectChanged()
 {
- QModelIndexList currentSelection = table->selectionModel()->selectedIndexes();
+ QModelIndexList currentSelection = ext_table->selectionModel()->selectedIndexes();
     int selCount = currentSelection.count();
     int firstRow = selCount > 0 ? currentSelection.at(1).row() : -1;
     int firstColumn = selCount > 0 ? currentSelection.at(1).column() : -1;
@@ -329,15 +345,15 @@
     emit statusMessage(selectedRowInfo);
 
     int nextRow = firstRow + 1;
- if (firstRow > -1 && firstColumn == 1 && !table->isRowHidden(nextRow))
+ if (firstRow > -1 && firstColumn == 1 && !ext_table->isRowHidden(nextRow))
     {
         deselectFirstCell(firstRow);
- table->hideRow(nextRow);
+ ext_table->hideRow(nextRow);
     }
- else if(firstRow > -1 && firstColumn == 1 && table->isRowHidden(nextRow))
+ else if(firstRow > -1 && firstColumn == 1 && ext_table->isRowHidden(nextRow))
     {
         deselectFirstCell(firstRow);
- table->showRow(nextRow);
+ ext_table->showRow(nextRow);
     }
 }
 

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/browser.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/browser.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/browser.h 2012-01-04 09:55:44 EST (Wed, 04 Jan 2012)
@@ -43,10 +43,12 @@
 #define BROWSER_H
 
 #include <QWidget>
+#include <QSqlTableModel>
 #include "exttableview.h"
 #include "ui_browserwidget.h"
 
 class ConnectionWidget;
+QT_FORWARD_DECLARE_CLASS(QSqlTableModel)
 QT_FORWARD_DECLARE_CLASS(QTableView)
 QT_FORWARD_DECLARE_CLASS(QPushButton)
 QT_FORWARD_DECLARE_CLASS(QTextEdit)
@@ -69,7 +71,8 @@
 
 public slots:
     void exec();
- void showTable(const QString &table);
+ QSqlTableModel* showTable(const QString &table);
+ void showTree(QSqlTableModel *model);
     void showMetaData(const QString &table);
     void addConnection();
     void openFile();
@@ -80,8 +83,13 @@
     { insertRow(); }
     void on_deleteRowAction_triggered()
     { deleteRow(); }
+
     void on_connectionWidget_tableActivated(const QString &table)
- { showTable(table); }
+ {
+ QSqlTableModel* model = showTable(table);
+ showTree(model);
+ }
+
     void on_connectionWidget_metaDataRequested(const QString &table)
     { showMetaData(table); }
     void on_submitButton_clicked()

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/browserwidget.ui
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/browserwidget.ui (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/browserwidget.ui 2012-01-04 09:55:44 EST (Wed, 04 Jan 2012)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
- <width>765</width>
- <height>515</height>
+ <width>850</width>
+ <height>516</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -86,7 +86,7 @@
        </sizepolicy>
       </property>
      </widget>
- <widget class="ExtTableView" name="table">
+ <widget class="ExtTableView" name="ext_table">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
         <horstretch>2</horstretch>
@@ -596,6 +596,7 @@
        <enum>QAbstractItemView::SelectRows</enum>
       </property>
      </widget>
+ <widget class="QTreeView" name="ext_tree"/>
     </widget>
    </item>
    <item>
@@ -725,7 +726,7 @@
   <tabstop>clearButton</tabstop>
   <tabstop>submitButton</tabstop>
   <tabstop>connectionWidget</tabstop>
- <tabstop>table</tabstop>
+ <tabstop>ext_table</tabstop>
  </tabstops>
  <resources/>
  <connections/>

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/media1.db
==============================================================================
Binary files. No diff available.


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk