diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 7189fe38..603b26a7 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -69,12 +69,18 @@ void EditDialog::loadText(const QByteArray& data, int row, int col) curCol = col; oldData = data; + // Load data QString textData = QString::fromUtf8(data.constData(), data.size()); ui->editorText->setPlainText(textData); - ui->editorText->setFocus(); - ui->editorText->selectAll(); hexEdit->setData(data); + // If we're in window mode (not in dock mode) focus the editor widget + if(!useInDock) + { + ui->editorText->setFocus(); + ui->editorText->selectAll(); + } + // Assume it's binary data and only call checkDatyType afterwards. This means the correct input widget is selected here in all cases // but once the user changed it to text input it will stay there. ui->editorStack->setCurrentIndex(1); @@ -218,3 +224,17 @@ void EditDialog::toggleOverwriteMode() hexEdit->setOverwriteMode(currentMode); ui->editorText->setOverwriteMode(currentMode); } + +void EditDialog::setFocus() +{ + QDialog::setFocus(); + + // When in dock mode set the focus to the editor widget. The idea here is that setting focus to the + // dock itself doesn't make much sense as it's just a frame; you'd have to tab to the editor which is what you + // most likely want to use. So in order to save the user from doing this we explicitly set the focus to the editor. + if(useInDock) + { + ui->editorText->setFocus(); + ui->editorText->selectAll(); + } +} diff --git a/src/EditDialog.h b/src/EditDialog.h index fae984e5..1928a862 100644 --- a/src/EditDialog.h +++ b/src/EditDialog.h @@ -17,13 +17,13 @@ public: explicit EditDialog(QWidget* parent = 0, bool forUseInDockWidget = false); ~EditDialog(); -public: int getCurrentCol() { return curCol; } int getCurrentRow() { return curRow; } public slots: virtual void reset(); virtual void loadText(const QByteArray& data, int row, int col); + virtual void setFocus(); protected: virtual void closeEvent(QCloseEvent* ev); diff --git a/src/ExtendedTableWidget.cpp b/src/ExtendedTableWidget.cpp index fe507723..d2391cbf 100644 --- a/src/ExtendedTableWidget.cpp +++ b/src/ExtendedTableWidget.cpp @@ -86,6 +86,10 @@ void ExtendedTableWidget::keyPressEvent(QKeyEvent* event) foreach(const QModelIndex& index, selectedIndexes()) model()->setData(index, ""); } + } else if(event->key() == Qt::Key_Return && selectedIndexes().count() == 1) { + // When hitting the return key simulate a double click. This way you can change the focus to the editor dock when pressing the + // return key for advanced editing, just like a double click would open the edit dialog + emit doubleClicked(selectedIndexes().at(0)); } // This prevents the current selection from being changed when pressing tab to move to the next filter. Note that this is in an 'if' condition, diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7ea6799c..42ef4b57 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -352,7 +352,12 @@ void MainWindow::populateTable(const QString& tablename) QApplication::setOverrideCursor(Qt::WaitCursor); // Set model + bool reconnectSelectionSignals = false; + if(ui->dataTable->model() == 0) + reconnectSelectionSignals = true; ui->dataTable->setModel(m_browseTableModel); + if(reconnectSelectionSignals) + connect(ui->dataTable->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(dataTableSelectionChanged(QModelIndex))); // Search stored table settings for this table QMap::ConstIterator tableIt; @@ -764,12 +769,14 @@ void MainWindow::doubleClickTable(const QModelIndex& index) editDock->loadText(index.data(Qt::EditRole).toByteArray(), index.row(), index.column()); // If the edit dock is visible don't open the edit window. If it's invisible open the edit window. - // The edit dock obviously doesn't need to be opened when it's already visible + // The edit dock obviously doesn't need to be opened when it's already visible but setting focus to it makes sense. if(!ui->dockEditWindow->isVisible()) editWin->show(); + else + editDock->setFocus(); } -void MainWindow::clickTable(const QModelIndex& index) +void MainWindow::dataTableSelectionChanged(const QModelIndex& index) { // Cancel on invalid index if(!index.isValid()) diff --git a/src/MainWindow.h b/src/MainWindow.h index 0522b478..bfce1195 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -178,7 +178,7 @@ private slots: void helpAbout(); void updateRecordText(int row, int col, const QByteArray& newtext); void editWinAway(); - void clickTable(const QModelIndex& index); + void dataTableSelectionChanged(const QModelIndex& index); void doubleClickTable(const QModelIndex& index); void executeQuery(); void importTableFromCSV(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 8e437707..611288a0 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -1279,7 +1279,7 @@ - Edit cell + Edit &cell 8 @@ -2791,22 +2791,6 @@ - - dataTable - clicked(QModelIndex) - MainWindow - clickTable(QModelIndex) - - - 59 - 118 - - - 518 - 314 - - - fileOpen() @@ -2867,6 +2851,5 @@ showRowidColumn(bool) browseDataSetTableEncoding() browseDataSetDefaultTableEncoding() - clickTable(QModelIndex)