@@ -51,6 +51,7 @@ MainWindow::MainWindow(QWidget* parent)
5151 : QMainWindow(parent),
5252 ui(new Ui::MainWindow),
5353 m_browseTableModel(new SqliteTableModel(this , &db, PreferencesDialog::getSettingsValue(" db" , " prefetchsize" ).toInt())),
54+ m_currentTabTableModel(m_browseTableModel),
5455 editWin(new EditDialog(this )),
5556 editDock(new EditDialog(this , true )),
5657 gotoValidator(new QIntValidator(0 , 0 , this ))
@@ -770,7 +771,7 @@ void MainWindow::helpAbout()
770771
771772void MainWindow::updateRecordText (int row, int col, bool isBlob, const QByteArray& newtext)
772773{
773- m_browseTableModel ->setTypedData (m_browseTableModel ->index (row, col), isBlob, newtext);
774+ m_currentTabTableModel ->setTypedData (m_currentTabTableModel ->index (row, col), isBlob, newtext);
774775}
775776
776777void MainWindow::editWinAway ()
@@ -793,8 +794,10 @@ void MainWindow::doubleClickTable(const QModelIndex& index)
793794 if (!index.isValid ())
794795 return ;
795796
796- // Don't allow editing of other objects than tables
797- bool allowEditing = db.getObjectByName (ui->comboBrowseTable ->currentText ()).gettype () == " table" ;
797+ // Don't allow editing of other objects than tables (on the browse table)
798+
799+ bool allowEditing = (m_currentTabTableModel == m_browseTableModel) && (db.getObjectByName (ui->comboBrowseTable ->currentText ()).gettype () == " table" );
800+
798801 editDock->allowEditing (allowEditing);
799802 editWin->allowEditing (allowEditing);
800803
@@ -816,8 +819,11 @@ void MainWindow::dataTableSelectionChanged(const QModelIndex& index)
816819 if (!index.isValid ())
817820 return ;
818821
822+ bool edit = (m_currentTabTableModel == m_browseTableModel) &&
823+ (db.getObjectByName (ui->comboBrowseTable ->currentText ()).gettype () == " table" );
824+
819825 // Don't allow editing of other objects than tables
820- editDock->allowEditing (db. getObjectByName (ui-> comboBrowseTable -> currentText ()). gettype () == " table " );
826+ editDock->allowEditing (edit );
821827
822828 // Load the current value into the edit dock only
823829 editDock->loadText (index.data (Qt::EditRole).toByteArray (), index.row (), index.column ());
@@ -963,20 +969,35 @@ void MainWindow::executeQuery()
963969 sqlWidget->finishExecution (statusMessage);
964970 updatePlot (sqlWidget->getModel ());
965971
972+ connect (sqlWidget->getTableResult (), SIGNAL (clicked (QModelIndex)), this , SLOT (dataTableSelectionChanged (QModelIndex)));
973+
974+ connect (sqlWidget->getTableResult (), SIGNAL (doubleClicked (QModelIndex)), this , SLOT (doubleClickTable (QModelIndex)));
975+
966976 if (!modified && !wasdirty)
967977 db.revertToSavepoint (); // better rollback, if the logic is not enough we can tune it.
968978}
969979
970980void MainWindow::mainTabSelected (int tabindex)
971981{
982+ editDock->allowEditing (false );
983+
972984 if (tabindex == 0 )
973985 {
974986 populateStructure ();
975987 } else if (tabindex == 1 ) {
988+ m_currentTabTableModel = m_browseTableModel;
976989 populateStructure ();
977990 resetBrowser ();
978991 } else if (tabindex == 2 ) {
979992 loadPragmas ();
993+ } else if (tabindex == 3 ) {
994+ SqlExecutionArea* sqlWidget = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas ->currentWidget ());
995+
996+ if (sqlWidget) {
997+ m_currentTabTableModel = sqlWidget->getModel ();
998+
999+ dataTableSelectionChanged (sqlWidget->getTableResult ()->currentIndex ());
1000+ }
9801001 }
9811002}
9821003
0 commit comments