Fix column widths in Execute SQL tab after multi-threading

This fixes the automatic column width adjustment in the Execute SQL tab
results view. This was broken by the introduction of multi-threaded
loading of the table data.
This commit is contained in:
Martin Kleusberg
2017-10-15 11:38:39 +02:00
parent 65454d02f3
commit 3ae4267a8b
2 changed files with 15 additions and 1 deletions

View File

@@ -12,7 +12,8 @@
SqlExecutionArea::SqlExecutionArea(DBBrowserDB& _db, QWidget* parent) :
QWidget(parent),
db(_db),
ui(new Ui::SqlExecutionArea)
ui(new Ui::SqlExecutionArea),
m_columnsResized(false)
{
// Create UI
ui->setupUi(this);
@@ -20,6 +21,7 @@ SqlExecutionArea::SqlExecutionArea(DBBrowserDB& _db, QWidget* parent) :
// Create model
model = new SqliteTableModel(db, this, Settings::getValue("db", "prefetchsize").toInt());
ui->tableResult->setModel(model);
connect(model, &SqliteTableModel::finishedFetch, this, &SqlExecutionArea::fetchedData);
// Load settings
reloadSettings();
@@ -42,7 +44,17 @@ QString SqlExecutionArea::getSelectedSql() const
void SqlExecutionArea::finishExecution(const QString& result)
{
m_columnsResized = false;
ui->editErrors->setPlainText(result);
}
void SqlExecutionArea::fetchedData()
{
// Don't resize the columns more than once to fit their contents. This is necessary because the finishedFetch signal of the model
// is emitted for each loaded prefetch block and we want to avoid resizes while scrolling down.
if(m_columnsResized)
return;
m_columnsResized = true;
// Set column widths according to their contents but make sure they don't exceed a certain size
ui->tableResult->resizeColumnsToContents();

View File

@@ -35,12 +35,14 @@ public slots:
virtual void saveAsCsv();
virtual void saveAsView();
virtual void reloadSettings();
void fetchedData();
private:
DBBrowserDB& db;
SqliteTableModel* model;
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
};
#endif