Skip to content

Commit

Permalink
EditDialog: Make edit dock more keyboard friendly to use
Browse files Browse the repository at this point in the history
  • Loading branch information
MKleusberg committed Dec 19, 2015
1 parent f26df79 commit 672b6f6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
24 changes: 22 additions & 2 deletions src/EditDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/EditDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class EditDialog : public QDialog
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);
Expand Down
4 changes: 4 additions & 0 deletions src/ExtendedTableWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, BrowseDataTableSettings>::ConstIterator tableIt;
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 1 addition & 18 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@
</widget>
<widget class="QDockWidget" name="dockEditWindow">
<property name="windowTitle">
<string>Edit cell</string>
<string>Edit &amp;cell</string>
</property>
<attribute name="dockWidgetArea">
<number>8</number>
Expand Down Expand Up @@ -2791,22 +2791,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>dataTable</sender>
<signal>clicked(QModelIndex)</signal>
<receiver>MainWindow</receiver>
<slot>clickTable(QModelIndex)</slot>
<hints>
<hint type="sourcelabel">
<x>59</x>
<y>118</y>
</hint>
<hint type="destinationlabel">
<x>518</x>
<y>314</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>fileOpen()</slot>
Expand Down Expand Up @@ -2867,6 +2851,5 @@
<slot>showRowidColumn(bool)</slot>
<slot>browseDataSetTableEncoding()</slot>
<slot>browseDataSetDefaultTableEncoding()</slot>
<slot>clickTable(QModelIndex)</slot>
</slots>
</ui>

0 comments on commit 672b6f6

Please sign in to comment.