EditDialog: Make edit dock more keyboard friendly to use

See #440, #441.
This commit is contained in:
Martin Kleusberg
2015-12-19 14:05:45 +01:00
parent f26df79961
commit 672b6f693b
6 changed files with 38 additions and 24 deletions

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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,

View File

@@ -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;
@@ -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())

View File

@@ -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();

View File

@@ -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>
@@ -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>
@@ -2867,6 +2851,5 @@
<slot>showRowidColumn(bool)</slot>
<slot>browseDataSetTableEncoding()</slot>
<slot>browseDataSetDefaultTableEncoding()</slot>
<slot>clickTable(QModelIndex)</slot>
</slots>
</ui>