aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dialogs/populatedialog.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2018-07-27 23:51:12 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2018-07-27 23:51:12 -0400
commitfeda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (patch)
tree1e50f5f666f419143f510d5ded00fe2006b7bd85 /SQLiteStudio3/guiSQLiteStudio/dialogs/populatedialog.cpp
parentd9aa870e5d509cc7309ab82dd102a937ab58613a (diff)
New upstream version 3.2.1+dfsg1upstream/3.2.1+dfsg1
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dialogs/populatedialog.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dialogs/populatedialog.cpp72
1 files changed, 58 insertions, 14 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/populatedialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/populatedialog.cpp
index 7861ff0..7f4ec20 100644
--- a/SQLiteStudio3/guiSQLiteStudio/dialogs/populatedialog.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/populatedialog.cpp
@@ -48,7 +48,10 @@ void PopulateDialog::init()
});
for (PopulatePlugin* plugin : plugins)
+ {
+ pluginByName[plugin->getName()] = plugin;
pluginTitles << plugin->getTitle();
+ }
widgetCover = new WidgetCover(this);
widgetCover->initWithInterruptContainer(tr("Abort"));
@@ -94,12 +97,29 @@ void PopulateDialog::deleteEngines(const QList<PopulateEngine*>& engines)
delete engine;
}
-void PopulateDialog::rebuildEngines()
+void PopulateDialog::rebuildEngines(const QHash<QString, QPair<QString, QVariant>>& columnConfig)
{
int row = 0;
+ QVariant config;
+ QString pluginName;
for (const ColumnEntry& entry : columnEntries)
{
- pluginSelected(entry.combo, entry.combo->currentIndex());
+ pluginName.clear();
+ if (columnConfig.contains(entry.column))
+ pluginName = columnConfig[entry.column].first;
+
+ if (pluginName.isNull())
+ {
+ pluginName = plugins[entry.combo->currentIndex()]->getName();
+ config = CFG->getPopulateHistory(pluginName);
+ }
+ else
+ {
+ entry.combo->setCurrentIndex(plugins.indexOf(pluginByName[pluginName]));
+ config = columnConfig[entry.column].second;
+ }
+
+ pluginSelected(entry.combo, entry.combo->currentIndex(), config);
updateColumnState(row++, false);
}
}
@@ -135,6 +155,8 @@ void PopulateDialog::refreshColumns()
return;
}
+ QString table = ui->tableCombo->currentText();
+
buttonMapper = new QSignalMapper(this);
connect(buttonMapper, SIGNAL(mapped(int)), this, SLOT(configurePlugin(int)));
@@ -142,14 +164,23 @@ void PopulateDialog::refreshColumns()
connect(checkMapper, SIGNAL(mapped(int)), this, SLOT(updateColumnState(int)));
SchemaResolver resolver(db);
- QStringList columns = resolver.getTableColumns(ui->tableCombo->currentText());
+ QStringList columns = resolver.getTableColumns(table);
QCheckBox* check = nullptr;
QComboBox* combo = nullptr;
QToolButton* btn = nullptr;
+
+ int rows = -1;
+ QHash<QString, QPair<QString, QVariant>> columnConfig = CFG->getPopulateHistory(db->getName(), table, rows);
+ if (rows > -1)
+ ui->rowsSpin->setValue(rows);
+
int row = 0;
for (const QString& column : columns)
{
check = new QCheckBox(column);
+ if (columnConfig.contains(column))
+ check->setChecked(true);
+
connect(check, SIGNAL(toggled(bool)), checkMapper, SLOT(map()));
checkMapper->setMapping(check, row);
@@ -165,11 +196,11 @@ void PopulateDialog::refreshColumns()
ui->columnsLayout->addWidget(check, row, 0);
ui->columnsLayout->addWidget(combo, row, 1);
ui->columnsLayout->addWidget(btn, row, 2);
- columnEntries << ColumnEntry(check, combo, btn);
+ columnEntries << ColumnEntry(column, check, combo, btn);
row++;
}
- rebuildEngines();
+ rebuildEngines(columnConfig);
QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
ui->columnsLayout->addItem(spacer, row, 0, 1, 3);
@@ -179,11 +210,15 @@ void PopulateDialog::refreshColumns()
void PopulateDialog::pluginSelected(int index)
{
+ QVariant config;
+ if (index >= 0 && index < plugins.size())
+ config = CFG->getPopulateHistory(plugins[index]->getName());
+
QComboBox* cb = dynamic_cast<QComboBox*>(sender());
- pluginSelected(cb, index);
+ pluginSelected(cb, index, config);
}
-void PopulateDialog::pluginSelected(QComboBox* combo, int index)
+void PopulateDialog::pluginSelected(QComboBox* combo, int index, const QVariant& config)
{
if (!combo)
return;
@@ -209,7 +244,11 @@ void PopulateDialog::pluginSelected(QComboBox* combo, int index)
if (index < 0 || index >= plugins.size())
return;
- entry->engine = plugins[index]->createEngine();
+ entry->plugin = plugins[index];
+ entry->engine = entry->plugin->createEngine();
+ if (config.isValid())
+ entry->engine->getConfig()->setValuesFromQVariant(config);
+
updateColumnState(columnIndex);
}
@@ -230,7 +269,8 @@ void PopulateDialog::configurePlugin(int index)
engine->getConfig()->savepoint();
- PopulateConfigDialog dialog(engine, columnEntries[index].check->text(), columnEntries[index].combo->currentText(), this);
+ QString colName = columnEntries[index].column;
+ PopulateConfigDialog dialog(engine, colName, columnEntries[index].combo->currentText(), this);
if (dialog.exec() != QDialog::Accepted)
engine->getConfig()->restore();
@@ -304,6 +344,7 @@ void PopulateDialog::accept()
if (!db)
return;
+ QHash<QString, QPair<QString, QVariant>> configForHistory;
QHash<QString,PopulateEngine*> engines;
for (ColumnEntry& entry : columnEntries)
{
@@ -313,16 +354,19 @@ void PopulateDialog::accept()
if (!entry.engine)
return;
- engines[entry.check->text()] = entry.engine;
-// entry.engine = nullptr; // to avoid deleting it in the entry's destructor - worker will delete it after it's done
+ engines[entry.column] = entry.engine;
+ // entry.engine = nullptr; // to avoid deleting it in the entry's destructor - worker will delete it after it's done
+
+ configForHistory[entry.column] = QPair<QString, QVariant>(entry.plugin->getName(), entry.engine->getConfig()->toQVariant());
}
QString table = ui->tableCombo->currentText();
- qint64 rows = ui->rowsSpin->value();
+ int rows = ui->rowsSpin->value();
started = true;
widgetCover->displayProgress(rows, "%v / %m");
widgetCover->show();
+ CFG->addPopulateHistory(db->getName(), table, rows, configForHistory);
POPULATE_MANAGER->populate(db, table, engines, rows);
}
@@ -334,8 +378,8 @@ void PopulateDialog::reject()
QDialog::reject();
}
-PopulateDialog::ColumnEntry::ColumnEntry(QCheckBox* check, QComboBox* combo, QToolButton* button) :
- check(check), combo(combo), button(button)
+PopulateDialog::ColumnEntry::ColumnEntry(const QString& column, QCheckBox* check, QComboBox* combo, QToolButton* button) :
+ column(column), check(check), combo(combo), button(button)
{
}