From 2e2e37098f0f58b1fe74291ef68264563d57f716 Mon Sep 17 00:00:00 2001 From: seatedscribe Date: Mon, 10 Apr 2017 17:39:54 +0200 Subject: [PATCH 1/2] [CSV import GUI] add option to choose dropdown menu field names from CSV This should also close #458 --- src/gui/csvImport/CsvImportWidget.cpp | 21 +- src/gui/csvImport/CsvImportWidget.h | 2 +- src/gui/csvImport/CsvImportWidget.ui | 588 +++++++++++--------------- 3 files changed, 261 insertions(+), 350 deletions(-) diff --git a/src/gui/csvImport/CsvImportWidget.cpp b/src/gui/csvImport/CsvImportWidget.cpp index ed00790f..1f71e2ad 100644 --- a/src/gui/csvImport/CsvImportWidget.cpp +++ b/src/gui/csvImport/CsvImportWidget.cpp @@ -92,6 +92,7 @@ CsvImportWidget::CsvImportWidget(QWidget *parent) connect(m_ui->comboBoxComment, SIGNAL(currentIndexChanged(int)), SLOT(parse())); connect(m_ui->comboBoxFieldSeparator, SIGNAL(currentIndexChanged(int)), SLOT(parse())); connect(m_ui->checkBoxBackslash, SIGNAL(toggled(bool)), SLOT(parse())); + connect(m_ui->checkBoxFieldNames, SIGNAL(toggled(bool)), SLOT(updatePreview())); connect(m_comboMapper, SIGNAL(mapped(int)), this, SLOT(comboChanged(int))); connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(writeDatabase())); @@ -131,16 +132,26 @@ void CsvImportWidget::updateTableview() { void CsvImportWidget::updatePreview() { + int minSkip = 0; + if (m_ui->checkBoxFieldNames->isChecked()) + minSkip = 1; m_ui->labelSizeRowsCols->setText(m_parserModel->getFileInfo()); - m_ui->spinBoxSkip->setValue(0); - m_ui->spinBoxSkip->setMaximum(qMax(0, m_parserModel->rowCount() - 1)); + m_ui->spinBoxSkip->setRange(minSkip, qMax(minSkip, m_parserModel->rowCount() - 1)); + m_ui->spinBoxSkip->setValue(minSkip); - int i; + int i, emptyId = 0; + QString columnName; QStringList list(tr("Not present in CSV file")); for (i = 1; i < m_parserModel->getCsvCols(); ++i) { - QString s = QString(tr("Column ")) + QString::number(i); - list << s; + if (m_ui->checkBoxFieldNames->isChecked()) { + columnName = m_parserModel->getCsvTable().at(0).at(i); + if (columnName.isEmpty()) + columnName = "<" + tr("Empty fieldname ") + QString::number(++emptyId) + ">"; + list << columnName; + } else { + list << QString(tr("column ")) + QString::number(i); + } } m_comboModel->setStringList(list); diff --git a/src/gui/csvImport/CsvImportWidget.h b/src/gui/csvImport/CsvImportWidget.h index aa463c08..9215fd36 100644 --- a/src/gui/csvImport/CsvImportWidget.h +++ b/src/gui/csvImport/CsvImportWidget.h @@ -53,6 +53,7 @@ private slots: void comboChanged(int comboId); void skippedChanged(int rows); void writeDatabase(); + void updatePreview(); void setRootGroup(); void reject(); @@ -68,7 +69,6 @@ private: KeePass2Writer m_writer; static const QStringList m_columnHeader; void configParser(); - void updatePreview(); void updateTableview(); Group* splitGroups(QString label); Group* hasChildren(Group* current, QString groupName); diff --git a/src/gui/csvImport/CsvImportWidget.ui b/src/gui/csvImport/CsvImportWidget.ui index 1b4bed72..df0af79f 100644 --- a/src/gui/csvImport/CsvImportWidget.ui +++ b/src/gui/csvImport/CsvImportWidget.ui @@ -6,15 +6,15 @@ 0 0 - 779 - 691 + 892 + 525 - + @@ -67,7 +67,23 @@ - + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 758 + 24 + + + + + @@ -91,48 +107,6 @@ Encoding - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 114 - 20 - - - - - - - - Qt::Horizontal - - - - 114 - 20 - - - - - - - - - 50 - false - - - - Consider '\' an escape character - - - @@ -149,167 +123,7 @@ - - - - - 50 - false - true - - - - - - - - - - - - 50 - false - - - - Fields are separated by - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 50 - false - - - - false - - - - - - - - 50 - false - - - - Comments start with - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 114 - 20 - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 50 - false - - - - false - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 114 - 20 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 114 - 20 - - - - - - - - - 50 - false - - - - Text is qualified by - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + @@ -334,79 +148,105 @@ - - - - Qt::Horizontal + + + + + 50 + false + - - QSizePolicy::Expanding + + Text is qualified by - + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + - 114 - 20 + 0 + 0 - + + + 50 + false + + + + false + + + + + + + + 50 + false + + + + Fields are separated by + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 50 + false + + + + false + + - - - - - - 50 - false - - - - Skip first - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 50 - false - - - - - - - - - 50 - false - - - - rows - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + 50 + false + + + + Comments start with + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + - + @@ -431,96 +271,112 @@ - + + + + + 50 + false + + + + First record has field names + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 50 + false + + + + Number of headers line to discard + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + false + + + + + + + Qt::Horizontal - 114 + 122 20 - - - - Qt::Horizontal + + + + + 0 + 0 + - - - 114 - 20 - + + + 50 + false + - + + Consider '\' an escape character + + + + + + + + 50 + false + true + + + + + + - - - - 0 - 0 - - - - - 75 - true - - - - Column layout - - - - - - 6 - - - 6 - - - 0 - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 758 - 24 - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - false - - - - @@ -569,6 +425,50 @@ + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + false + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Column layout + + + + + + 6 + + + 6 + + + 0 + + + + + + From eb7f4d2eaabfe314ef670c58458375db4e15b156 Mon Sep 17 00:00:00 2001 From: seatedscribe Date: Thu, 27 Apr 2017 22:11:26 +0200 Subject: [PATCH 2/2] Apply requested changes --- src/gui/csvImport/CsvImportWidget.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/csvImport/CsvImportWidget.cpp b/src/gui/csvImport/CsvImportWidget.cpp index 1f71e2ad..93cba84c 100644 --- a/src/gui/csvImport/CsvImportWidget.cpp +++ b/src/gui/csvImport/CsvImportWidget.cpp @@ -139,11 +139,11 @@ void CsvImportWidget::updatePreview() { m_ui->spinBoxSkip->setRange(minSkip, qMax(minSkip, m_parserModel->rowCount() - 1)); m_ui->spinBoxSkip->setValue(minSkip); - int i, emptyId = 0; + int emptyId = 0; QString columnName; QStringList list(tr("Not present in CSV file")); - for (i = 1; i < m_parserModel->getCsvCols(); ++i) { + for (int i = 1; i < m_parserModel->getCsvCols(); ++i) { if (m_ui->checkBoxFieldNames->isChecked()) { columnName = m_parserModel->getCsvTable().at(0).at(i); if (columnName.isEmpty()) @@ -155,13 +155,13 @@ void CsvImportWidget::updatePreview() { } m_comboModel->setStringList(list); - i=1; + int j=1; for (QComboBox* b : m_combos) { - if (i < m_parserModel->getCsvCols()) - b->setCurrentIndex(i); + if (j < m_parserModel->getCsvCols()) + b->setCurrentIndex(j); else b->setCurrentIndex(0); - ++i; + ++j; } }