1010#include < QDateTime>
1111#include < QKeyEvent>
1212
13- EditTableDialog::EditTableDialog (DBBrowserDB* db, const QString& tableName, bool createTable, QWidget* parent)
13+ EditTableDialog::EditTableDialog (DBBrowserDB& db, const QString& tableName, bool createTable, QWidget* parent)
1414 : QDialog(parent),
1515 ui(new Ui::EditTableDialog),
1616 pdb(db),
@@ -28,7 +28,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, bool
2828 if (m_bNewTable == false )
2929 {
3030 // Existing table, so load and set the current layout
31- QString sTablesql = pdb-> getObjectByName (curTable).getsql ();
31+ QString sTablesql = pdb. getObjectByName (curTable).getsql ();
3232 QPair<sqlb::Table, bool > parse_result = sqlb::Table::parseSQL (sTablesql );
3333 m_table = parse_result.first ;
3434 ui->labelEditWarning ->setVisible (!parse_result.second );
@@ -39,7 +39,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, bool
3939 }
4040
4141 // And create a savepoint
42- pdb-> setSavepoint (m_sRestorePointName);
42+ pdb. setSavepoint (m_sRestorePointName);
4343
4444 // Update UI
4545 ui->editTableName ->setText (curTable);
@@ -138,12 +138,12 @@ void EditTableDialog::accept()
138138 if (m_bNewTable)
139139 {
140140 // Creation of new table
141- if (!pdb-> executeSQL (m_table.sql ()))
141+ if (!pdb. executeSQL (m_table.sql ()))
142142 {
143143 QMessageBox::warning (
144144 this ,
145145 QApplication::applicationName (),
146- tr (" Error creating table. Message from database engine:\n %1" ).arg (pdb-> lastErrorMessage ));
146+ tr (" Error creating table. Message from database engine:\n %1" ).arg (pdb. lastErrorMessage ));
147147 return ;
148148 }
149149 } else {
@@ -152,9 +152,9 @@ void EditTableDialog::accept()
152152 // Rename table if necessary
153153 if (ui->editTableName ->text () != curTable)
154154 {
155- if (!pdb-> renameTable (curTable, ui->editTableName ->text ()))
155+ if (!pdb. renameTable (curTable, ui->editTableName ->text ()))
156156 {
157- QMessageBox::warning (this , QApplication::applicationName (), pdb-> lastErrorMessage );
157+ QMessageBox::warning (this , QApplication::applicationName (), pdb. lastErrorMessage );
158158 return ;
159159 }
160160 }
@@ -166,7 +166,7 @@ void EditTableDialog::accept()
166166void EditTableDialog::reject ()
167167{
168168 // Then rollback to our savepoint
169- pdb-> revertToSavepoint (m_sRestorePointName);
169+ pdb. revertToSavepoint (m_sRestorePointName);
170170
171171 QDialog::reject ();
172172}
@@ -206,7 +206,7 @@ void EditTableDialog::updateTypes()
206206
207207 m_table.fields ().at (index)->setType (type);
208208 if (!m_bNewTable)
209- pdb-> renameColumn (curTable, column, m_table.fields ().at (index));
209+ pdb. renameColumn (curTable, column, m_table.fields ().at (index));
210210 checkInput ();
211211 }
212212}
@@ -239,7 +239,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
239239 if (!m_bNewTable)
240240 {
241241 sqlb::FieldVector pk = m_table.primaryKey ();
242- foreach (const DBBrowserObject& fkobj, pdb-> objMap .values (" table" ))
242+ foreach (const DBBrowserObject& fkobj, pdb. objMap .values (" table" ))
243243 {
244244 QList<sqlb::ConstraintPtr> fks = fkobj.table .constraints (sqlb::FieldVector (), sqlb::Constraint::ForeignKeyConstraintType);
245245 foreach (sqlb::ConstraintPtr fkptr, fks)
@@ -303,9 +303,9 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
303303 // Because our renameColumn() function fails when setting a column to Not Null when it already contains some NULL values
304304 // we need to check for this case and cancel here. Maybe we can think of some way to modify the INSERT INTO ... SELECT statement
305305 // to at least replace all troublesome NULL values by the default value
306- SqliteTableModel m (this , pdb );
306+ SqliteTableModel m (pdb, this );
307307 m.setQuery (QString (" SELECT COUNT(%1) FROM %2 WHERE %3 IS NULL;" )
308- .arg (sqlb::escapeIdentifier (pdb-> getObjectByName (curTable).table .rowidColumn ()))
308+ .arg (sqlb::escapeIdentifier (pdb. getObjectByName (curTable).table .rowidColumn ()))
309309 .arg (sqlb::escapeIdentifier (curTable))
310310 .arg (sqlb::escapeIdentifier (field->name ())));
311311 if (m.data (m.index (0 , 0 )).toInt () > 0 )
@@ -330,7 +330,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
330330 // First check if the contents of this column are all integers. If not this field cannot be set to AI
331331 if (!m_bNewTable)
332332 {
333- SqliteTableModel m (this , pdb );
333+ SqliteTableModel m (pdb, this );
334334 m.setQuery (QString (" SELECT COUNT(*) FROM %1 WHERE %2 <> CAST(%3 AS INTEGER);" )
335335 .arg (sqlb::escapeIdentifier (curTable))
336336 .arg (sqlb::escapeIdentifier (field->name ()))
@@ -374,7 +374,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
374374 if (!m_bNewTable && item->checkState (column) == Qt::Checked)
375375 {
376376 // Because our renameColumn() function fails when setting a column to unique when it already contains the same values
377- SqliteTableModel m (this , pdb );
377+ SqliteTableModel m (pdb, this );
378378 m.setQuery (QString (" SELECT COUNT(%2) FROM %1;" ).arg (sqlb::escapeIdentifier (curTable)).arg (sqlb::escapeIdentifier (field->name ())));
379379 int rowcount = m.data (m.index (0 , 0 )).toInt ();
380380 m.setQuery (QString (" SELECT COUNT(DISTINCT %2) FROM %1;" ).arg (sqlb::escapeIdentifier (curTable)).arg (sqlb::escapeIdentifier (field->name ())));
@@ -441,7 +441,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
441441 }
442442
443443 if (callRenameColumn)
444- pdb-> renameColumn (curTable, oldFieldName, field);
444+ pdb. renameColumn (curTable, oldFieldName, field);
445445 }
446446
447447 checkInput ();
@@ -498,7 +498,7 @@ void EditTableDialog::addField()
498498
499499 // Actually add the new column to the table if we're editing an existing table
500500 if (!m_bNewTable)
501- pdb-> addColumn (curTable, f);
501+ pdb. addColumn (curTable, f);
502502
503503 checkInput ();
504504}
@@ -526,12 +526,12 @@ void EditTableDialog::removeField()
526526 QString msg = tr (" Are you sure you want to delete the field '%1'?\n All data currently stored in this field will be lost." ).arg (ui->treeWidget ->currentItem ()->text (0 ));
527527 if (QMessageBox::warning (this , QApplication::applicationName (), msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
528528 {
529- if (!pdb-> renameColumn (curTable, ui->treeWidget ->currentItem ()->text (0 ), sqlb::FieldPtr ()))
529+ if (!pdb. renameColumn (curTable, ui->treeWidget ->currentItem ()->text (0 ), sqlb::FieldPtr ()))
530530 {
531- QMessageBox::warning (0 , QApplication::applicationName (), pdb-> lastErrorMessage );
531+ QMessageBox::warning (0 , QApplication::applicationName (), pdb. lastErrorMessage );
532532 } else {
533533 // relayout
534- QString sTablesql = pdb-> getObjectByName (curTable).getsql ();
534+ QString sTablesql = pdb. getObjectByName (curTable).getsql ();
535535 m_table = sqlb::Table::parseSQL (sTablesql ).first ;
536536 populateFields ();
537537 }
@@ -604,17 +604,17 @@ void EditTableDialog::moveCurrentField(bool down)
604604 // Editing an old one
605605
606606 // Move the actual column
607- if (!pdb-> renameColumn (
607+ if (!pdb. renameColumn (
608608 curTable,
609609 ui->treeWidget ->currentItem ()->text (0 ),
610610 m_table.fields ().at (ui->treeWidget ->indexOfTopLevelItem (ui->treeWidget ->currentItem ())),
611611 (down ? 1 : -1 )
612612 ))
613613 {
614- QMessageBox::warning (0 , QApplication::applicationName (), pdb-> lastErrorMessage );
614+ QMessageBox::warning (0 , QApplication::applicationName (), pdb. lastErrorMessage );
615615 } else {
616616 // Reload table SQL
617- QString sTablesql = pdb-> getObjectByName (curTable).getsql ();
617+ QString sTablesql = pdb. getObjectByName (curTable).getsql ();
618618 m_table = sqlb::Table::parseSQL (sTablesql ).first ;
619619 populateFields ();
620620
0 commit comments