Fix layout of CSV Import Widget

This commit is contained in:
Jonathan White 2020-06-21 09:16:33 -04:00
parent ef7a4288ae
commit 60bb593228
3 changed files with 671 additions and 531 deletions

View File

@ -39,69 +39,26 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
, m_comboModel(new QStringListModel(this))
, m_columnHeader(QStringList() << QObject::tr("Group") << QObject::tr("Title") << QObject::tr("Username")
<< QObject::tr("Password") << QObject::tr("URL") << QObject::tr("Notes")
<< QObject::tr("Last Modified") << QObject::tr("Created")
/* << QObject::tr("Future field1") */)
{
m_ui->setupUi(this);
m_ui->comboBoxCodec->addItems(QStringList() << "UTF-8"
<< "Windows-1252"
<< "UTF-16"
<< "UTF-16LE");
m_ui->comboBoxFieldSeparator->addItems(QStringList() << ","
<< ";"
<< "-"
<< ":"
<< "."
<< "TAB (\\t)");
m_fieldSeparatorList = QStringList() << ","
<< QObject::tr("Last Modified") << QObject::tr("Created"))
, m_fieldSeparatorList(QStringList() << ","
<< ";"
<< "-"
<< ":"
<< "."
<< "\t";
m_ui->comboBoxTextQualifier->addItems(QStringList() << "\""
<< "'"
<< ":"
<< "."
<< "|");
m_ui->comboBoxComment->addItems(QStringList() << "#"
<< ";"
<< ":"
<< "@");
<< "\t")
{
m_ui->setupUi(this);
m_ui->tableViewFields->setSelectionMode(QAbstractItemView::NoSelection);
m_ui->tableViewFields->setFocusPolicy(Qt::NoFocus);
m_ui->messageWidget->setHidden(true);
for (int i = 0; i < m_columnHeader.count(); ++i) {
QLabel* label = new QLabel(m_columnHeader.at(i), this);
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
QFont font = label->font();
font.setBold(false);
label->setFont(font);
m_combos << m_ui->groupCombo << m_ui->titleCombo << m_ui->usernameCombo << m_ui->passwordCombo << m_ui->urlCombo
<< m_ui->notesCombo << m_ui->lastModifiedCombo << m_ui->createdCombo;
QComboBox* combo = new QComboBox(this);
font = combo->font();
font.setBold(false);
combo->setFont(font);
m_combos.append(combo);
for (auto combo : m_combos) {
combo->setModel(m_comboModel);
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] { comboChanged(combo, i); });
#else
connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=] {
comboChanged(combo, i);
});
#endif
// layout labels and combo fields in column-first order
int combo_rows = 1 + (m_columnHeader.count() - 1) / 2;
int x = i % combo_rows;
int y = 2 * (i / combo_rows);
m_ui->gridLayout_combos->addWidget(label, x, y);
m_ui->gridLayout_combos->addWidget(combo, x, y + 1);
QSpacerItem* item = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
m_ui->gridLayout_combos->addItem(item, x, y + 2);
connect(combo, SIGNAL(currentIndexChanged(int)), SLOT(comboChanged(int)));
}
m_parserModel->setHeaderLabels(m_columnHeader);
@ -119,12 +76,10 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
void CsvImportWidget::comboChanged(QComboBox* currentSender, int comboId)
void CsvImportWidget::comboChanged(int index)
{
if (currentSender->currentIndex() != -1) {
// this line is the one that actually updates GUI table
m_parserModel->mapColumns(currentSender->currentIndex(), comboId);
}
// this line is the one that actually updates GUI table
m_parserModel->mapColumns(index, m_combos.indexOf(qobject_cast<QComboBox*>(sender())));
updateTableview();
}
@ -167,19 +122,17 @@ void CsvImportWidget::updatePreview()
m_ui->spinBoxSkip->setRange(minSkip, qMax(minSkip, m_parserModel->rowCount() - 1));
m_ui->spinBoxSkip->setValue(minSkip);
int emptyId = 0;
QString columnName;
QStringList list(tr("Not present in CSV file"));
QStringList list(tr("Not Present"));
for (int i = 1; i < m_parserModel->getCsvCols(); ++i) {
if (m_ui->checkBoxFieldNames->isChecked()) {
columnName = m_parserModel->getCsvTable().at(0).at(i);
auto columnName = m_parserModel->getCsvTable().at(0).at(i);
if (columnName.isEmpty()) {
columnName = "<" + tr("Empty fieldname %1").arg(++emptyId) + ">";
list << QString(tr("Column %1").arg(i));
} else {
list << columnName;
}
list << columnName;
} else {
list << QString(tr("column %1").arg(i));
list << QString(tr("Column %1").arg(i));
}
}
m_comboModel->setStringList(list);
@ -221,7 +174,6 @@ void CsvImportWidget::parse()
} else {
m_ui->messageWidget->setHidden(true);
}
QWidget::adjustSize();
}
QString CsvImportWidget::formatStatusText() const

View File

@ -49,7 +49,7 @@ signals:
private slots:
void parse();
void comboChanged(QComboBox* currentSender, int comboId);
void comboChanged(int index);
void skippedChanged(int rows);
void writeDatabase();
void updatePreview();

File diff suppressed because it is too large Load Diff