Skip to content

Commit

Permalink
ExportCsvDialog: Set table selection to current table in Browse Data tab
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MKleusberg committed Feb 14, 2014
1 parent 393a58b commit 4cd5131
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/ExportCsvDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <QMessageBox>
#include <QFileDialog>

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),
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ExportCsvDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 4cd5131

Please sign in to comment.