Skip to content

Commit

Permalink
Export to CSV the currently browsed data as displayed
Browse files Browse the repository at this point in the history
A new option is added to the Browse Data tab toolbar for exporting the data
of the browsed table as currently displayed (after filters, display formats
and order column) to a CSV file. This is done in coherence to the same
popup options in the SQL tab for execution results.

See issue #1402
  • Loading branch information
mgrojo committed Jun 1, 2018
1 parent 39302f5 commit e50022c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 8 deletions.
13 changes: 12 additions & 1 deletion src/MainWindow.cpp
Expand Up @@ -185,6 +185,12 @@ void MainWindow::init()
ui->actionSqlResultsSave->setMenu(popupSaveSqlResultsMenu);
qobject_cast<QToolButton*>(ui->toolbarSql->widgetForAction(ui->actionSqlResultsSave))->setPopupMode(QToolButton::InstantPopup);

popupSaveFilterAsMenu = new QMenu(this);
popupSaveFilterAsMenu->addAction(ui->actionFilteredTableExportCsv);
popupSaveFilterAsMenu->addAction(ui->actionFilterSaveAsView);
ui->buttonSaveFilterAsPopup->setMenu(popupSaveFilterAsMenu);
ui->buttonSaveFilterAsPopup->setPopupMode(QToolButton::InstantPopup);

popupBrowseDataHeaderMenu = new QMenu(this);
popupBrowseDataHeaderMenu->addAction(ui->actionShowRowidColumn);
popupBrowseDataHeaderMenu->addAction(ui->actionUnlockViewEditing);
Expand Down Expand Up @@ -1600,7 +1606,7 @@ void MainWindow::activateFields(bool enable)
ui->actionSaveProject->setEnabled(enable);
ui->actionEncryption->setEnabled(enable && write);
ui->buttonClearFilters->setEnabled(enable);
ui->buttonSaveFilterAsView->setEnabled(enable);
ui->buttonSaveFilterAsPopup->setEnabled(enable);
ui->dockEdit->setEnabled(enable);
ui->dockPlot->setEnabled(enable);

Expand Down Expand Up @@ -2954,6 +2960,11 @@ void MainWindow::saveAsView(QString query)
QMessageBox::warning(this, qApp->applicationName(), tr("Error creating view: %1").arg(db.lastError()));
}

void MainWindow::exportFilteredTable()
{
ExportDataDialog dialog(db, ExportDataDialog::ExportFormatCsv, this, m_browseTableModel->customQuery(false));
dialog.exec();
}

void MainWindow::saveFilterAsView()
{
Expand Down
2 changes: 2 additions & 0 deletions src/MainWindow.h
Expand Up @@ -142,6 +142,7 @@ class MainWindow : public QMainWindow
QMenu* recentFilesMenu;
QMenu* popupSaveSqlFileMenu;
QMenu* popupSaveSqlResultsMenu;
QMenu* popupSaveFilterAsMenu;
QMenu* popupBrowseDataHeaderMenu;

QLabel* statusEncodingLabel;
Expand Down Expand Up @@ -281,6 +282,7 @@ private slots:
void setFindFrameVisibility(bool show);
void openFindReplaceDialog();
void saveFilterAsView();
void exportFilteredTable();
};

#endif
74 changes: 67 additions & 7 deletions src/MainWindow.ui
Expand Up @@ -167,12 +167,12 @@ You can drag SQL statements from an object row and drop them into other applicat
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonSaveFilterAsView">
<widget class="QToolButton" name="buttonSaveFilterAsPopup">
<property name="toolTip">
<string>Save the current filter, sort column and display formats as a view</string>
<string>Save the table as currently displayed</string>
</property>
<property name="whatsThis">
<string>This button saves the current setting of the browsed table (filters, display formats and order column) as an SQL view that you can later browse or use in SQL statements.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This popup menu provides the following options applying to the currently browsed and filtered table:&lt;/p&gt;&lt;ul style=&quot;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;&quot;&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Export to CSV: this option exports the data of the browsed table as currently displayed (after filters, display formats and order column) to a CSV file.&lt;/li&gt;&lt;li style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Save as view: this option saves the current setting of the browsed table (filters, display formats and order column) as an SQL view that you can later browse or use in SQL statements.&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>...</string>
Expand Down Expand Up @@ -396,8 +396,8 @@ You can drag SQL statements from an object row and drop them into other applicat
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<height>531</height>
<width>601</width>
<height>484</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
Expand Down Expand Up @@ -887,7 +887,7 @@ You can drag SQL statements from an object row and drop them into other applicat
<x>0</x>
<y>0</y>
<width>1037</width>
<height>25</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="fileMenu">
Expand Down Expand Up @@ -2041,6 +2041,34 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
<string>Extra DB Toolbar</string>
</property>
</action>
<action name="actionFilteredTableExportCsv">
<property name="text">
<string>Export to &amp;CSV</string>
</property>
<property name="toolTip">
<string>Export the filtered data to CSV</string>
</property>
<property name="statusTip">
<string>Export the filtered data to CSV</string>
</property>
<property name="whatsThis">
<string>This button exports the data of the browsed table as currently displayed (after filters, display formats and order column) as a CSV file.</string>
</property>
</action>
<action name="actionFilterSaveAsView">
<property name="text">
<string>Save as &amp;view</string>
</property>
<property name="toolTip">
<string>Save the current filter, sort column and display formats as a view</string>
</property>
<property name="statusTip">
<string>Save the current filter, sort column and display formats as a view</string>
</property>
<property name="whatsThis">
<string>This button saves the current setting of the browsed table (filters, display formats and order column) as an SQL view that you can later browse or use in SQL statements.</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down Expand Up @@ -3206,7 +3234,7 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
</hints>
</connection>
<connection>
<sender>buttonSaveFilterAsView</sender>
<sender>buttonSaveFilterAsPopup</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>saveFilterAsView()</slot>
Expand Down Expand Up @@ -3301,6 +3329,38 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
</hint>
</hints>
</connection>
<connection>
<sender>actionFilteredTableExportCsv</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>exportFilteredTable()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>518</x>
<y>314</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionFilterSaveAsView</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>saveFilterAsView()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>518</x>
<y>314</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>fileOpen()</slot>
Expand Down

0 comments on commit e50022c

Please sign in to comment.