Skip to content
Snippets Groups Projects
Commit ad587afa authored by Juan Manuel Carmona Loaiza's avatar Juan Manuel Carmona Loaiza :ghost:
Browse files

Reload csv on separator change

parent 42c7aa27
No related branches found
No related tags found
No related merge requests found
...@@ -95,7 +95,7 @@ QBoxLayout* CsvImportAssistant::createLayout() ...@@ -95,7 +95,7 @@ QBoxLayout* CsvImportAssistant::createLayout()
m_separatorField = new QLineEdit(QString("")); m_separatorField = new QLineEdit(QString(""));
m_separatorField->setMaxLength(1); m_separatorField->setMaxLength(1);
m_separatorField->setMaximumWidth(50); m_separatorField->setMaximumWidth(50);
connect(m_separatorField, &QLineEdit::editingFinished, this, &CsvImportAssistant::Reload); connect(m_separatorField, &QLineEdit::editingFinished, this, &CsvImportAssistant::reloadCsvFile);
//First Row SpinBox //First Row SpinBox
m_firstDataRowSpinBox = new QSpinBox(); m_firstDataRowSpinBox = new QSpinBox();
...@@ -133,7 +133,7 @@ QBoxLayout* CsvImportAssistant::createLayout() ...@@ -133,7 +133,7 @@ QBoxLayout* CsvImportAssistant::createLayout()
auto tableLayout = new QVBoxLayout; auto tableLayout = new QVBoxLayout;
tableLayout->setMargin(10); tableLayout->setMargin(10);
tableLayout->addWidget(new QLabel("Right click on the table or use the controls below to modify what will be imported")); tableLayout->addWidget(new QLabel("Right click on the table or use the controls below to modify what will be imported"));
tableLayout->addWidget(m_columnTypeSelector); //tableLayout->addWidget(m_columnTypeSelector);
tableLayout->addWidget(m_tableWidget); tableLayout->addWidget(m_tableWidget);
//place separator_field, single_column_spinbox and first_row: //place separator_field, single_column_spinbox and first_row:
...@@ -177,6 +177,19 @@ void CsvImportAssistant::Reload() ...@@ -177,6 +177,19 @@ void CsvImportAssistant::Reload()
} }
} }
void CsvImportAssistant::reloadCsvFile(){
reset();
try {
if(!m_fileName.isEmpty())
m_csvFile = std::make_unique<CSVFile>(m_fileName.toStdString(), separator());
}
catch (...) {
showErrorMessage("There was a problem opening the file \"" + m_fileName.toStdString() + "\"");
return;
}
Reload();
}
void CsvImportAssistant::onRejectButton(){ void CsvImportAssistant::onRejectButton(){
reject(); reject();
} }
...@@ -188,7 +201,7 @@ void CsvImportAssistant::onImportButton() ...@@ -188,7 +201,7 @@ void CsvImportAssistant::onImportButton()
auto data = getData(); auto data = getData();
accept(); accept();
} catch(std::exception& e){ } catch(std::exception& e){
QString message = QString("Unable to import, check the following error message may help:\n") + QString::fromStdString(e.what()); QString message = QString("Unable to import, the following exception was thrown:\n") + QString::fromStdString(e.what());
QMessageBox::warning(nullptr, "Wrong data format", message); QMessageBox::warning(nullptr, "Wrong data format", message);
} }
} }
......
...@@ -57,6 +57,7 @@ private: ...@@ -57,6 +57,7 @@ private:
QBoxLayout* createFileDetailsLayout(); QBoxLayout* createFileDetailsLayout();
char guessSeparator() const; char guessSeparator() const;
void reloadCsvFile();
void generate_table(); void generate_table();
void set_table_data(std::vector<std::vector<std::string>> dataArray); void set_table_data(std::vector<std::vector<std::string>> dataArray);
void removeBlankColumns(std::vector<std::vector<std::string>> &dataArray); void removeBlankColumns(std::vector<std::vector<std::string>> &dataArray);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment