Skip to content

Commit 18b9a56

Browse files
committed
Tabbing added
1 parent d651aea commit 18b9a56

13 files changed

+608
-217
lines changed

BrowseWidget.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
BrowseWidget::BrowseWidget(QWidget *parent) :
1717
QWidget(parent),
1818
m_model(NULL),
19+
m_schemaWidget(NULL),
1920
ui(new Ui::BrowseWidget)
2021
{
2122
ui->setupUi(this);
@@ -30,13 +31,25 @@ BrowseWidget::~BrowseWidget()
3031
delete ui;
3132
}
3233

33-
void BrowseWidget::setDatabase(QSqlDatabase *database)
34+
void BrowseWidget::init(QSqlDatabase *database, Extension *extension)
3435
{
35-
// Set the database
36+
// Set the database and extension
3637
m_database = database;
38+
m_extension = extension;
3739

3840
// Setup the model
3941
m_model = new QSqlTableModel(this, (*m_database));
42+
43+
// Make sure we save changes when moving to a new row (this is necessary so "Add" works)
44+
connect(ui->tableView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
45+
46+
// Setup schema widget (if supported by extension)
47+
if (m_extension && m_extension->hasCapability(VIEW_SCHEMA)) {
48+
m_schemaWidget = new SchemaWidget(this, m_database, m_extension);
49+
m_schemaWidget->init();
50+
ui->tabWidget->addTab(m_schemaWidget, QIcon::fromTheme("document-edit"), "Schema");
51+
//connect(m_schemaWidget, SIGNAL(refreshNeeded()), this, SLOT(refresh())); // @TODO make this refresh
52+
}
4053
}
4154

4255
bool BrowseWidget::setTable(QString table)
@@ -74,6 +87,11 @@ bool BrowseWidget::setTable(QString table)
7487
ui->tableView->sortByColumn(0, Qt::AscendingOrder);
7588
ui->tableView->setAlternatingRowColors(true);
7689

90+
// If there is a schema-editor, then set the table
91+
if (m_schemaWidget) {
92+
m_schemaWidget->setTable(table);
93+
}
94+
7795
return true;
7896
}
7997

@@ -113,9 +131,6 @@ void BrowseWidget::on_addButton_clicked()
113131

114132
// Select the newly inserted row
115133
ui->tableView->selectRow(m_model->rowCount()-1);
116-
117-
// Make sure we save changes when moving to a new row (this is necessary so "Add" works)
118-
connect(ui->tableView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
119134
}
120135

121136
void BrowseWidget::on_clearButton_clicked()
@@ -140,6 +155,9 @@ void BrowseWidget::commitChanges()
140155
// Check if there was an error and display it if there was
141156
if (m_model->lastError().type() != QSqlError::NoError) {
142157
QMessageBox::critical(this, "Operation failed", m_model->lastError().text());
158+
159+
// Revert changes and set back to onFieldChange
160+
m_model->revertAll();
143161
}
144162
}
145163
}
@@ -152,9 +170,6 @@ void BrowseWidget::currentChanged(QModelIndex previous, QModelIndex current)
152170
// Commit changes
153171
commitChanges();
154172

155-
// There's no reason to call this anymore, we don't need to know if the row has changed
156-
disconnect(ui->tableView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
157-
158173
// Revert back to OnFieldChange
159174
m_model->setEditStrategy(QSqlTableModel::OnFieldChange);
160175
}
@@ -171,3 +186,12 @@ void BrowseWidget::on_saveAsButton_clicked()
171186
// Execute the dialog
172187
exportSelectionDialog.exec();
173188
}
189+
190+
void BrowseWidget::refresh()
191+
{
192+
// If there is a schema widget (extension supports it), refresh it
193+
/*if (m_schemaWidget) {
194+
m_schemaWidget->setTable(m_table);
195+
}*/
196+
// @TODO this can cause errors if the table no longer exists
197+
}

BrowseWidget.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <QSqlDatabase>
66
#include <QSqlTableModel>
77

8+
#include "SchemaWidget.h"
9+
810
namespace Ui {
911
class BrowseWidget;
1012
}
@@ -17,7 +19,7 @@ class BrowseWidget : public QWidget
1719
explicit BrowseWidget(QWidget *parent = 0);
1820
~BrowseWidget();
1921

20-
void setDatabase(QSqlDatabase *database);
22+
void init(QSqlDatabase *database, Extension *extension = NULL);
2123

2224
bool setTable(QString table);
2325

@@ -36,17 +38,25 @@ private slots:
3638

3739
void on_saveAsButton_clicked();
3840

41+
void refresh();
42+
3943
private:
4044
Ui::BrowseWidget *ui;
4145

4246
// Database
4347
QSqlDatabase *m_database;
4448

49+
// Extension
50+
Extension *m_extension;
51+
4552
// Model for table
4653
QSqlTableModel *m_model;
4754

4855
// Current Table
4956
QString m_table;
57+
58+
// Schema Widget
59+
SchemaWidget *m_schemaWidget;
5060
};
5161

5262
#endif // BROWSEWIDGET_H

0 commit comments

Comments
 (0)