Skip to content

Commit

Permalink
Merge pull request #165 from ehb54/master
Browse files Browse the repository at this point in the history
merge master into release-2024-Q4
  • Loading branch information
ehb54 authored Dec 14, 2024
2 parents c3be3cd + 9c767ad commit 10a7397
Show file tree
Hide file tree
Showing 17 changed files with 1,375 additions and 938 deletions.
1,317 changes: 640 additions & 677 deletions gui/us_csv_loader.cpp

Large diffs are not rendered by default.

163 changes: 58 additions & 105 deletions gui/us_csv_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

#include "us_widgets.h"
#include "us_widgets_dialog.h"
#include "us_csv_data.h"
#include <QTableWidget>
#include <QSortFilterProxyModel>
#include <QTableWidgetItem>
#include <QTableView>
#include <QStandardItem>
#include <QStandardItemModel>


//! \class CSVTableView
//! \brief A class to provide a custom QTableView for CSV data with context menu options for deleting rows and columns.
class CSVTableView : public QTableView {
Expand All @@ -22,11 +24,16 @@ class CSVTableView : public QTableView {
*/
CSVTableView(QWidget *parent = nullptr);

signals:
/*!
* \brief Signal emitted when a row or column is deleted.
*/
void row_column_deleted();
signals:
/*!
* \brief Signal emitted when a row is deleted.
*/
void row_deleted();

/*!
* \brief Signal emitted when a column is deleted.
*/
void column_deleted();

protected:
/*!
Expand All @@ -36,10 +43,10 @@ class CSVTableView : public QTableView {
void contextMenuEvent(QContextMenuEvent *event) override;

private slots:
/*!
* \brief Slot to handle deletion of rows.
*/
void delete_rows();
/*!
* \brief Slot to handle deletion of rows.
*/
void delete_rows();

/*!
* \brief Slot to handle deletion of columns.
Expand Down Expand Up @@ -71,82 +78,27 @@ class CSVSortFilterProxyModel : public QSortFilterProxyModel {
class US_GUI_EXTERN US_CSV_Loader : public US_WidgetsDialog {
Q_OBJECT

public:
//! \class CSV_Data
//! \brief A nested class to hold CSV data.
class US_GUI_EXTERN CSV_Data {
public:
/*!
* \brief Get the number of columns.
* \return Number of columns.
*/
int columnCount();

/*!
* \brief Get the number of rows.
* \return Number of rows.
*/
int rowCount();

/*!
* \brief Get the header labels.
* \return Header labels.
*/
QStringList header();

/*!
* \brief Get data for a specific column.
* \param column The column index.
* \return Data for the specified column.
*/
QVector<double> columnAt(int column);

/*!
* \brief Set the CSV data.
* \param filePath The file path.
* \param headers The header labels.
* \param columns The column data.
* \return True if the data was set successfully, otherwise false.
*/
bool setData(const QString &filePath, const QStringList &headers, const QVector<QVector<double>> &columns);

/*!
* \brief Get the file path.
* \return The file path.
*/
QString filePath();

/*!
* \brief Clear the CSV data.
*/
void clear();

private:
QStringList m_header; /*!< Header labels. */
QVector<QVector<double>> m_columns; /*!< Column data. */
QString m_path; /*!< File path. */
};

/*!
* \brief Constructor for US_CSV_Loader.
* \param filePath The file path of the CSV file.
* \param note An optional note.
* \param editable Flag indicating if the data is editable.
* \param parent The parent widget.
*/
US_CSV_Loader(const QString &filePath, const QString &note = "", bool editable = false, QWidget *parent = 0);

/*!
* \brief Get the loaded CSV data.
* \return The loaded CSV data.
*/
CSV_Data data();

/*!
* \brief Get the error message if any.
* \return The error message.
*/
QString error_message();
public:
/*!
* \brief Constructor for US_CSV_Loader.
* \param filePath CSV file path.
* \param note An optional note.
* \param editable If it is true, all table items are editable.
* \param parent Parent widget.
*/
US_CSV_Loader(const QString &filePath, const QString &note = "", bool editable = false, QWidget *parent = 0);

/*!
* \brief Get the loaded CSV data.
* \return Return CSV data.
*/
US_CSV_Data data();

/*!
* \brief Get the error message if any.
* \return Return the error message.
*/
QString error_message();

private:
enum DELIMITER { TAB, COMMA, SEMICOLON, SPACE, OTHER, NONE }; /*!< Enum for delimiter types. */
Expand Down Expand Up @@ -174,7 +126,7 @@ QString error_message();
CSVTableView *tv_data; /*!< Table view for CSV data. */
QStandardItemModel *model; /*!< Standard item model for CSV data. */
CSVSortFilterProxyModel *proxy; /*!< Proxy model for sorting CSV data. */
CSV_Data csv_data; /*!< CSV data. */
US_CSV_Data csv_data; /*!< CSV data. */

/*!
* \brief Set up the user interface.
Expand All @@ -186,14 +138,14 @@ QString error_message();
* \param filePath The file path of the CSV file.
* \return True if the file was parsed successfully, otherwise false.
*/
bool parse_file(const QString &filePath);
bool parse_file(const QString&);

/*!
* \brief Generate a list of alphabetic column headers.
* \param count The number of headers to generate.
* \return The list of alphabetic column headers.
*/
QStringList gen_alpha_list(int count);
QStringList gen_alpha_list(int);

/*!
* \brief Check the validity of the table.
Expand All @@ -202,20 +154,16 @@ QString error_message();
bool check_table();

/*!
* \brief Get sorted data from the table.
* \param sortedData The sorted data.
* \param headers The headers of the sorted data.
*/
void get_sorted(QVector<QVector<double>> &sortedData, QStringList &headers);
* \brief Check the validity of the header.
*/
void check_header();

/*!
* \brief Write data to a CSV file.
* \param filePath The file path.
* \param delimiter The delimiter to use.
* \param error_msg The error message if any.
* \return True if the data was written successfully, otherwise false.
*/
bool write_csv(const QString &filePath, const QString &delimiter, QString &error_msg);
* \brief Make CSV Data for report
* \return True the CSV_Data is made.
*/
bool make_csv_data(QString&);


private slots:

Expand Down Expand Up @@ -243,13 +191,13 @@ private slots:
* \brief Slot to fill the table with data.
* \param columnCount The number of columns.
*/
void fill_table(int columnCount);
void fill_table(int );

/*!
* \brief Slot to handle change of delimiter.
* \param delimiter The new delimiter.
*/
void new_delimiter(const QString &delimiter);
void new_delimiter(const QString&);

/*!
* \brief Slot to add a header row.
Expand All @@ -260,17 +208,22 @@ private slots:
* \brief Slot to handle item change in the table.
* \param item The changed item.
*/
void item_changed(QStandardItem *item);
void item_changed(QStandardItem*);

/*!
* \brief Slot to relabel the headers.
*/
void relabel();

/*!
* \brief Slot to handle row or column deletion.
* \brief Slot to handle column deletion.
*/
void column_deleted();

/*!
* \brief Slot to handle row deletion.
*/
void row_column_deleted();
void row_deleted();

/*!
* \brief Slot to show red colored items.
Expand Down
13 changes: 7 additions & 6 deletions gui/us_extinction_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,16 @@ US_Extinction::US_Extinction() : US_Widgets()
// {
// QStringList files;
// QFile f;

// QFileDialog dialog (this);
// //dialog.setNameFilter(tr("Text (*.txt *.csv *.dat *.wa *.dsp)"));

// dialog.setNameFilter(tr("Text files (*.[Tt][Xx][Tt] *.[Cc][Ss][Vv] *.[Dd][Aa][Tt] *.[Ww][Aa]* *.[Dd][Ss][Pp]);;All files (*)"));

// dialog.setFileMode(QFileDialog::ExistingFiles);
// dialog.setViewMode(QFileDialog::Detail);
// //dialog.setDirectory("/home/alexsav/ultrascan/data/spectra");

// QString work_dir_data = US_Settings::dataDir();
// //qDebug() << work_dir_data;
// //dialog.setDirectory(work_dir_data);
Expand All @@ -452,7 +452,7 @@ US_Extinction::US_Extinction() : US_Widgets()

void US_Extinction::add_wavelength(void)
{
QString filter = "csv files (*.csv);;dat files (*.dat);;text files (*.txt);;dsp files (*.dsp);; wa files (*.wa)";
QString filter = "Text Files (*.csv *.dat *.txt *.dsp *.wa);; All Files (*)";
QString fpath = QFileDialog::getOpenFileName(this, "Load The Target Spectrum",
US_Settings::dataDir(), filter);
if (fpath.isEmpty()) {
Expand All @@ -462,7 +462,7 @@ void US_Extinction::add_wavelength(void)
US_CSV_Loader *csv_loader = new US_CSV_Loader(fpath, note, true, this);
int state = csv_loader->exec();
if (state != QDialog::Accepted) return;
US_CSV_Loader::CSV_Data csv_data = csv_loader->data();
US_CSV_Data csv_data = csv_loader->data();
if (csv_data.columnCount() < 2) return;
loadScan(csv_data);
update_data();
Expand All @@ -487,7 +487,8 @@ bool US_Extinction::isComment(const QString &str)
return(true);
}
}
bool US_Extinction::loadScan(US_CSV_Loader::CSV_Data& csv_data)

bool US_Extinction::loadScan(US_CSV_Data& csv_data)
{
QRegularExpression re;
re.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
Expand Down
2 changes: 1 addition & 1 deletion gui/us_extinction_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class US_GUI_EXTERN US_Extinction : public US_Widgets
//! \brief Slot to load scan data.
//! \param data Reference to CSV_Data.
//! \return True if scan is loaded successfully.
bool loadScan(US_CSV_Loader::CSV_Data& data);
bool loadScan(US_CSV_Data& data);

//! \brief Check if a line is a comment.
//! \param line The line to check.
Expand Down
Loading

0 comments on commit 10a7397

Please sign in to comment.