Skip to content

Commit

Permalink
enabled copy and paste for catalog view table
Browse files Browse the repository at this point in the history
  • Loading branch information
heterophyllus committed Apr 12, 2022
1 parent 5ecbb37 commit 94c1ffd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/catalog_view_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

#include <QListWidget>
#include <QDialog>
#include <QMenu>
#include <QMessageBox>
#include <QFileDialog>
#include <QDebug>

#include "glass_catalog_manager.h"
Expand Down Expand Up @@ -79,6 +82,10 @@ CatalogViewForm::CatalogViewForm(QMdiArea *parent) :
// set up default table
m_currentPropertyList << "nd" << "ne" << "vd" << "ve" << "PgF";
m_currentDigit = 5;

m_table->setContextMenuPolicy(Qt::CustomContextMenu);
QObject::connect(m_table, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showContextMenuOnTable()));

this->update();
}

Expand Down Expand Up @@ -309,3 +316,24 @@ void CatalogViewForm::showSettingDlg()
delete dlg;
}

void CatalogViewForm::showContextMenuOnTable()
{
QMenu contextMenu;
QAction *action1 = contextMenu.addAction("Export Data");
QObject::connect(action1, SIGNAL(triggered()), this, SLOT(exportCSV()));
contextMenu.exec(QCursor::pos());
}

void CatalogViewForm::exportCSV()
{
QString filePath = QFileDialog::getSaveFileName(this, tr("Save as"),"",tr("CSV file(*.csv);;All Files(*.*)"));
if(filePath.isEmpty()){
return;
}

if(m_table->exportCSV(filePath)){
QMessageBox::information(this, "Success", "The data was successfully exported");
}else{
QMessageBox::warning(this, "Error", "Failed to export");
}
}
10 changes: 6 additions & 4 deletions src/catalog_view_form.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
#include <QWidget>
#include <QMdiArea>
#include <QList>
#include <QTableWidget>
#include <QComboBox>
#include <QtMath>

#include "glass_catalog.h"
#include "qcustomtablewidget.h"

namespace Ui {
class CatalogViewForm;
Expand All @@ -52,13 +52,15 @@ private slots:
void setUpTable(QStringList properties,GlassCatalog* catalog, int digit=6);
void showDatasheet();
void showSettingDlg();
void showContextMenuOnTable();
void exportCSV();

private:
Ui::CatalogViewForm *ui;

QMdiArea* m_parentMdiArea;
QTableWidget* m_table;
QComboBox* m_comboBox;
QMdiArea* m_parentMdiArea;
QCustomTableWidget* m_table;
QComboBox* m_comboBox;

QStringList m_allPropertyList;
QStringList m_currentPropertyList;
Expand Down
9 changes: 8 additions & 1 deletion src/catalog_view_form.ui
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,17 @@
</spacer>
</item>
<item row="1" column="0" colspan="4">
<widget class="QTableWidget" name="tableWidget"/>
<widget class="QCustomTableWidget" name="tableWidget"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QCustomTableWidget</class>
<extends>QTableWidget</extends>
<header>src/qcustomtablewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 94c1ffd

Please sign in to comment.