Skip to content

Commit 87e1b9b

Browse files
committed
Usability improvements for Extended Table Widget and SQL
results pane Copy for multi-line text data surrounds the text with the <pre> tag in the HTML version for avoiding line white-space adjustments in the pasted text. See #1058 Do not use binary data in the "Use as Filter" option. Indicate the existence of an error in the background of the SQL results frame. The error-indicators is reused for disabling this functionality. When nothing is shown, a placeholder text hints the objective of the results pane. The preference label for the font size of this pane is modified for consistency (SQL Log is another widget).
1 parent e60e9ff commit 87e1b9b

6 files changed

+36
-9
lines changed

src/ExtendedTableWidget.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,14 @@ void ExtendedTableWidget::copy(const bool withHeaders)
260260
QVariant data = index.data(Qt::EditRole);
261261

262262
// Table cell data
263-
htmlResult.append(data.toString().toHtmlEscaped());
264-
// non-NULL data is enquoted, whilst NULL isn't
263+
QString text = data.toString();
264+
if (text.contains('\n'))
265+
htmlResult.append("<pre>" + data.toString().toHtmlEscaped() + "</pre>");
266+
else
267+
htmlResult.append(data.toString().toHtmlEscaped());
268+
269+
// non-NULL data is enquoted in plain text format, whilst NULL isn't
265270
if (!data.isNull()) {
266-
QString text = data.toString();
267271
text.replace("\"", "\"\"");
268272
result.append(QString("\"%1\"").arg(text));
269273
}
@@ -409,9 +413,10 @@ void ExtendedTableWidget::paste()
409413
void ExtendedTableWidget::useAsFilter()
410414
{
411415
QModelIndex index = selectionModel()->currentIndex();
416+
SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model());
412417

413418
// Abort if there's nothing to filter
414-
if (!index.isValid() || !selectionModel()->hasSelection())
419+
if (!index.isValid() || !selectionModel()->hasSelection() || m->isBinary(index))
415420
return;
416421

417422
QVariant data = model()->data(index, Qt::EditRole);

src/MainWindow.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,7 @@ void MainWindow::executeQuery()
10281028
int sql3status = SQLITE_OK;
10291029
int tail_length = utf8Query.length();
10301030
QString statusMessage;
1031+
bool ok = false;
10311032
bool modified = false;
10321033
bool wasdirty = db.getDirty();
10331034
bool structure_updated = false;
@@ -1139,26 +1140,30 @@ void MainWindow::executeQuery()
11391140

11401141
modified = true;
11411142
statusMessage = tr("Query executed successfully: %1 (took %2ms%3)").arg(queryPart.trimmed()).arg(timer.elapsed()).arg(stmtHasChangedDatabase);
1143+
ok = true;
11421144
break;
11431145
}
11441146
case SQLITE_MISUSE:
11451147
continue;
11461148
default:
11471149
statusMessage = QString::fromUtf8(sqlite3_errmsg(db._db)) + ": " + queryPart;
1150+
ok = true;
11481151
break;
11491152
}
11501153
timer.restart();
11511154
} else {
11521155
statusMessage = QString::fromUtf8(sqlite3_errmsg(db._db)) + ": " + queryPart;
11531156
sqlWidget->getEditor()->setErrorIndicator(execution_start_line, execution_start_index, execution_start_line, execution_end_index);
1157+
ok = false;
1158+
11541159
}
11551160

11561161
execution_start_index = execution_end_index;
11571162

11581163
// Process events to keep the UI responsive
11591164
qApp->processEvents();
11601165
}
1161-
sqlWidget->finishExecution(statusMessage);
1166+
sqlWidget->finishExecution(statusMessage, ok);
11621167
plotDock->updatePlot(sqlWidget->getModel());
11631168

11641169
connect(sqlWidget->getTableResult(), &ExtendedTableWidget::activated, this, &MainWindow::dataTableSelectionChanged);

src/PreferencesDialog.ui

+2-2
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@
818818
<item row="2" column="0">
819819
<widget class="QLabel" name="label_7">
820820
<property name="text">
821-
<string>SQL &amp;log font size</string>
821+
<string>SQL &amp;results font size</string>
822822
</property>
823823
<property name="buddy">
824824
<cstring>spinLogFontSize</cstring>
@@ -881,7 +881,7 @@
881881
<item row="5" column="1">
882882
<widget class="QCheckBox" name="checkErrorIndicators">
883883
<property name="toolTip">
884-
<string>Enabling error indicators highlights the SQL code lines that caused errors during the last execution</string>
884+
<string>When set, the SQL code lines that caused errors during the last execution are highlighted and the results frame indicates the error in the background</string>
885885
</property>
886886
<property name="text">
887887
<string>enabled</string>

src/SqlExecutionArea.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,17 @@ QString SqlExecutionArea::getSelectedSql() const
5555
return ui->editEditor->selectedText().trimmed().replace(QChar(0x2029), '\n');
5656
}
5757

58-
void SqlExecutionArea::finishExecution(const QString& result)
58+
void SqlExecutionArea::finishExecution(const QString& result, const bool ok)
5959
{
6060
m_columnsResized = false;
6161
ui->editErrors->setPlainText(result);
62+
// Set reddish background when not ok
63+
if (showErrorIndicators)
64+
if (ok)
65+
ui->editErrors->setStyleSheet("");
66+
else
67+
ui->editErrors->setStyleSheet("color: white; background-color: rgb(255, 102, 102)");
68+
6269
}
6370

6471
void SqlExecutionArea::fetchedData()
@@ -135,6 +142,12 @@ void SqlExecutionArea::reloadSettings()
135142

136143
// Set prefetch settings
137144
model->setChunkSize(Settings::getValue("db", "prefetchsize").toInt());
145+
146+
// Check if error indicators are enabled for the not-ok background clue
147+
showErrorIndicators = Settings::getValue("editor", "error_indicators").toBool();
148+
if (!showErrorIndicators)
149+
ui->editErrors->setStyleSheet("");
150+
138151
}
139152

140153
void SqlExecutionArea::find(QString expr, bool forward)

src/SqlExecutionArea.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SqlExecutionArea : public QWidget
3131
ExtendedTableWidget *getTableResult();
3232

3333
public slots:
34-
virtual void finishExecution(const QString& result);
34+
virtual void finishExecution(const QString& result, const bool ok);
3535
virtual void saveAsCsv();
3636
virtual void saveAsView();
3737
virtual void reloadSettings();
@@ -54,6 +54,7 @@ private slots:
5454
QString sqlFileName;
5555
Ui::SqlExecutionArea* ui;
5656
bool m_columnsResized; // This is set to true if the columns of the table view were already adjusted to fit their contents
57+
bool showErrorIndicators;
5758
};
5859

5960
#endif

src/SqlExecutionArea.ui

+3
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@
227227
<property name="readOnly">
228228
<bool>true</bool>
229229
</property>
230+
<property name="placeholderText">
231+
<string>Results of the last executed statements</string>
232+
</property>
230233
</widget>
231234
</widget>
232235
</widget>

0 commit comments

Comments
 (0)