Skip to content


Browse files Browse the repository at this point in the history
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).
  • Loading branch information
mgrojo committed Nov 18, 2017
1 parent e60e9ff commit 87e1b9b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/ExtendedTableWidget.cpp
Expand Up @@ -260,10 +260,14 @@ void ExtendedTableWidget::copy(const bool withHeaders)
QVariant data =;

// Table cell data
// non-NULL data is enquoted, whilst NULL isn't
QString text = data.toString();
if (text.contains('\n'))
htmlResult.append("<pre>" + data.toString().toHtmlEscaped() + "</pre>");

// non-NULL data is enquoted in plain text format, whilst NULL isn't
if (!data.isNull()) {
QString text = data.toString();
text.replace("\"", "\"\"");
Expand Down Expand Up @@ -409,9 +413,10 @@ void ExtendedTableWidget::paste()
void ExtendedTableWidget::useAsFilter()
QModelIndex index = selectionModel()->currentIndex();
SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model());

// Abort if there's nothing to filter
if (!index.isValid() || !selectionModel()->hasSelection())
if (!index.isValid() || !selectionModel()->hasSelection() || m->isBinary(index))

QVariant data = model()->data(index, Qt::EditRole);
Expand Down
7 changes: 6 additions & 1 deletion src/MainWindow.cpp
Expand Up @@ -1028,6 +1028,7 @@ void MainWindow::executeQuery()
int sql3status = SQLITE_OK;
int tail_length = utf8Query.length();
QString statusMessage;
bool ok = false;
bool modified = false;
bool wasdirty = db.getDirty();
bool structure_updated = false;
Expand Down Expand Up @@ -1139,26 +1140,30 @@ void MainWindow::executeQuery()

modified = true;
statusMessage = tr("Query executed successfully: %1 (took %2ms%3)").arg(queryPart.trimmed()).arg(timer.elapsed()).arg(stmtHasChangedDatabase);
ok = true;
statusMessage = QString::fromUtf8(sqlite3_errmsg(db._db)) + ": " + queryPart;
ok = true;
} else {
statusMessage = QString::fromUtf8(sqlite3_errmsg(db._db)) + ": " + queryPart;
sqlWidget->getEditor()->setErrorIndicator(execution_start_line, execution_start_index, execution_start_line, execution_end_index);
ok = false;


execution_start_index = execution_end_index;

// Process events to keep the UI responsive
sqlWidget->finishExecution(statusMessage, ok);

connect(sqlWidget->getTableResult(), &ExtendedTableWidget::activated, this, &MainWindow::dataTableSelectionChanged);
Expand Down
4 changes: 2 additions & 2 deletions src/PreferencesDialog.ui
Expand Up @@ -818,7 +818,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>SQL &amp;log font size</string>
<string>SQL &amp;results font size</string>
<property name="buddy">
Expand Down Expand Up @@ -881,7 +881,7 @@
<item row="5" column="1">
<widget class="QCheckBox" name="checkErrorIndicators">
<property name="toolTip">
<string>Enabling error indicators highlights the SQL code lines that caused errors during the last execution</string>
<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>
<property name="text">
Expand Down
15 changes: 14 additions & 1 deletion src/SqlExecutionArea.cpp
Expand Up @@ -55,10 +55,17 @@ QString SqlExecutionArea::getSelectedSql() const
return ui->editEditor->selectedText().trimmed().replace(QChar(0x2029), '\n');

void SqlExecutionArea::finishExecution(const QString& result)
void SqlExecutionArea::finishExecution(const QString& result, const bool ok)
m_columnsResized = false;
// Set reddish background when not ok
if (showErrorIndicators)
if (ok)
ui->editErrors->setStyleSheet("color: white; background-color: rgb(255, 102, 102)");


void SqlExecutionArea::fetchedData()
Expand Down Expand Up @@ -135,6 +142,12 @@ void SqlExecutionArea::reloadSettings()

// Set prefetch settings
model->setChunkSize(Settings::getValue("db", "prefetchsize").toInt());

// Check if error indicators are enabled for the not-ok background clue
showErrorIndicators = Settings::getValue("editor", "error_indicators").toBool();
if (!showErrorIndicators)


void SqlExecutionArea::find(QString expr, bool forward)
Expand Down
3 changes: 2 additions & 1 deletion src/SqlExecutionArea.h
Expand Up @@ -31,7 +31,7 @@ class SqlExecutionArea : public QWidget
ExtendedTableWidget *getTableResult();

public slots:
virtual void finishExecution(const QString& result);
virtual void finishExecution(const QString& result, const bool ok);
virtual void saveAsCsv();
virtual void saveAsView();
virtual void reloadSettings();
Expand All @@ -54,6 +54,7 @@ private slots:
QString sqlFileName;
Ui::SqlExecutionArea* ui;
bool m_columnsResized; // This is set to true if the columns of the table view were already adjusted to fit their contents
bool showErrorIndicators;

3 changes: 3 additions & 0 deletions src/SqlExecutionArea.ui
Expand Up @@ -227,6 +227,9 @@
<property name="readOnly">
<property name="placeholderText">
<string>Results of the last executed statements</string>
Expand Down

0 comments on commit 87e1b9b

Please sign in to comment.