Permalink
Browse files

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 87e1b9bc7c51b86fca2c3192929500fd457022eb
Showing with 36 additions and 9 deletions.
  1. +9 −4 src/ExtendedTableWidget.cpp
  2. +6 −1 src/MainWindow.cpp
  3. +2 −2 src/PreferencesDialog.ui
  4. +14 −1 src/SqlExecutionArea.cpp
  5. +2 −1 src/SqlExecutionArea.h
  6. +3 −0 src/SqlExecutionArea.ui
@@ -260,10 +260,14 @@ void ExtendedTableWidget::copy(const bool withHeaders)
QVariant data = index.data(Qt::EditRole);

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

// non-NULL data is enquoted in plain text format, whilst NULL isn't
if (!data.isNull()) {
QString text = data.toString();
text.replace("\"", "\"\"");
result.append(QString("\"%1\"").arg(text));
}
@@ -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))
return;

QVariant data = model()->data(index, Qt::EditRole);
@@ -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;
@@ -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;
break;
}
case SQLITE_MISUSE:
continue;
default:
statusMessage = QString::fromUtf8(sqlite3_errmsg(db._db)) + ": " + queryPart;
ok = true;
break;
}
timer.restart();
} 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
qApp->processEvents();
}
sqlWidget->finishExecution(statusMessage);
sqlWidget->finishExecution(statusMessage, ok);
plotDock->updatePlot(sqlWidget->getModel());

connect(sqlWidget->getTableResult(), &ExtendedTableWidget::activated, this, &MainWindow::dataTableSelectionChanged);
@@ -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>
<property name="buddy">
<cstring>spinLogFontSize</cstring>
@@ -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>
<property name="text">
<string>enabled</string>
@@ -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;
ui->editErrors->setPlainText(result);
// Set reddish background when not ok
if (showErrorIndicators)
if (ok)
ui->editErrors->setStyleSheet("");
else
ui->editErrors->setStyleSheet("color: white; background-color: rgb(255, 102, 102)");

}

void SqlExecutionArea::fetchedData()
@@ -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)
ui->editErrors->setStyleSheet("");

}

void SqlExecutionArea::find(QString expr, bool forward)
@@ -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();
@@ -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;
};

#endif
@@ -227,6 +227,9 @@
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Results of the last executed statements</string>
</property>
</widget>
</widget>
</widget>

0 comments on commit 87e1b9b

Please sign in to comment.