From 4cd5131d1ade56d8f190df3fbd6a19730eb1dfce Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 14 Feb 2014 16:22:51 +0100 Subject: [PATCH] ExportCsvDialog: Set table selection to current table in Browse Data tab When called while the Browse Data tab of the main window is selected also select the current table or view in the ExportCsvDialog. Sort the table names in the combobox of the ExportCsvDialog. --- src/ExportCsvDialog.cpp | 9 ++++++++- src/ExportCsvDialog.h | 2 +- src/MainWindow.cpp | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/ExportCsvDialog.cpp b/src/ExportCsvDialog.cpp index 895b92d5..de80a54e 100644 --- a/src/ExportCsvDialog.cpp +++ b/src/ExportCsvDialog.cpp @@ -9,7 +9,7 @@ #include #include -ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, QWidget* parent, const QString& query) +ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, QWidget* parent, const QString& query, const QString& selection) : QDialog(parent), ui(new Ui::ExportCsvDialog), pdb(db), @@ -25,6 +25,13 @@ ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, QWidget* parent, const QString objectMap objects = pdb->getBrowsableObjects(); for(objectMap::ConstIterator i=objects.begin();i!=objects.end();++i) ui->comboTable->addItem(QIcon(QString(":icons/%1").arg(i.value().gettype())), i.value().getname()); + + // Sort list of tables and select the table specified in the selection parameter or alternatively the first one + ui->comboTable->model()->sort(0); + if(selection.isEmpty()) + ui->comboTable->setCurrentIndex(0); + else + ui->comboTable->setCurrentIndex(ui->comboTable->findText(selection)); } else { // Hide table combo box ui->labelTable->setVisible(false); diff --git a/src/ExportCsvDialog.h b/src/ExportCsvDialog.h index 32a45f86..b4934515 100644 --- a/src/ExportCsvDialog.h +++ b/src/ExportCsvDialog.h @@ -14,7 +14,7 @@ class ExportCsvDialog : public QDialog Q_OBJECT public: - explicit ExportCsvDialog(DBBrowserDB* db, QWidget* parent = 0, const QString& query = ""); + explicit ExportCsvDialog(DBBrowserDB* db, QWidget* parent = 0, const QString& query = "", const QString& selection = ""); ~ExportCsvDialog(); private slots: diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index cc913fdd..566d33d7 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -738,7 +738,13 @@ void MainWindow::importTableFromCSV() void MainWindow::exportTableToCSV() { - ExportCsvDialog dialog(&db, this); + // Get the current table name if we are in the Browse Data tab + QString current_table; + if(ui->mainTab->currentIndex() == 1) + current_table = ui->comboBrowseTable->currentText(); + + // Open dialog + ExportCsvDialog dialog(&db, this, "", current_table); dialog.exec(); }