mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-04 15:39:34 +01:00
Fix layout of CSV Import Widget
This commit is contained in:
@@ -39,69 +39,26 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
|
|||||||
, m_comboModel(new QStringListModel(this))
|
, m_comboModel(new QStringListModel(this))
|
||||||
, m_columnHeader(QStringList() << QObject::tr("Group") << QObject::tr("Title") << QObject::tr("Username")
|
, m_columnHeader(QStringList() << QObject::tr("Group") << QObject::tr("Title") << QObject::tr("Username")
|
||||||
<< QObject::tr("Password") << QObject::tr("URL") << QObject::tr("Notes")
|
<< QObject::tr("Password") << QObject::tr("URL") << QObject::tr("Notes")
|
||||||
<< QObject::tr("Last Modified") << QObject::tr("Created")
|
<< QObject::tr("Last Modified") << QObject::tr("Created"))
|
||||||
/* << QObject::tr("Future field1") */)
|
, m_fieldSeparatorList(QStringList() << ","
|
||||||
{
|
|
||||||
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() << ","
|
|
||||||
<< ";"
|
<< ";"
|
||||||
<< "-"
|
<< "-"
|
||||||
<< ":"
|
<< ":"
|
||||||
<< "."
|
<< "."
|
||||||
<< "\t";
|
<< "\t")
|
||||||
m_ui->comboBoxTextQualifier->addItems(QStringList() << "\""
|
{
|
||||||
<< "'"
|
m_ui->setupUi(this);
|
||||||
<< ":"
|
|
||||||
<< "."
|
|
||||||
<< "|");
|
|
||||||
m_ui->comboBoxComment->addItems(QStringList() << "#"
|
|
||||||
<< ";"
|
|
||||||
<< ":"
|
|
||||||
<< "@");
|
|
||||||
m_ui->tableViewFields->setSelectionMode(QAbstractItemView::NoSelection);
|
m_ui->tableViewFields->setSelectionMode(QAbstractItemView::NoSelection);
|
||||||
m_ui->tableViewFields->setFocusPolicy(Qt::NoFocus);
|
m_ui->tableViewFields->setFocusPolicy(Qt::NoFocus);
|
||||||
m_ui->messageWidget->setHidden(true);
|
m_ui->messageWidget->setHidden(true);
|
||||||
|
|
||||||
for (int i = 0; i < m_columnHeader.count(); ++i) {
|
m_combos << m_ui->groupCombo << m_ui->titleCombo << m_ui->usernameCombo << m_ui->passwordCombo << m_ui->urlCombo
|
||||||
QLabel* label = new QLabel(m_columnHeader.at(i), this);
|
<< m_ui->notesCombo << m_ui->lastModifiedCombo << m_ui->createdCombo;
|
||||||
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
||||||
QFont font = label->font();
|
|
||||||
font.setBold(false);
|
|
||||||
label->setFont(font);
|
|
||||||
|
|
||||||
QComboBox* combo = new QComboBox(this);
|
for (auto combo : m_combos) {
|
||||||
font = combo->font();
|
|
||||||
font.setBold(false);
|
|
||||||
combo->setFont(font);
|
|
||||||
m_combos.append(combo);
|
|
||||||
combo->setModel(m_comboModel);
|
combo->setModel(m_comboModel);
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
|
connect(combo, SIGNAL(currentIndexChanged(int)), SLOT(comboChanged(int)));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_parserModel->setHeaderLabels(m_columnHeader);
|
m_parserModel->setHeaderLabels(m_columnHeader);
|
||||||
@@ -119,12 +76,10 @@ CsvImportWidget::CsvImportWidget(QWidget* parent)
|
|||||||
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
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
|
||||||
// this line is the one that actually updates GUI table
|
m_parserModel->mapColumns(index, m_combos.indexOf(qobject_cast<QComboBox*>(sender())));
|
||||||
m_parserModel->mapColumns(currentSender->currentIndex(), comboId);
|
|
||||||
}
|
|
||||||
updateTableview();
|
updateTableview();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,19 +122,17 @@ void CsvImportWidget::updatePreview()
|
|||||||
m_ui->spinBoxSkip->setRange(minSkip, qMax(minSkip, m_parserModel->rowCount() - 1));
|
m_ui->spinBoxSkip->setRange(minSkip, qMax(minSkip, m_parserModel->rowCount() - 1));
|
||||||
m_ui->spinBoxSkip->setValue(minSkip);
|
m_ui->spinBoxSkip->setValue(minSkip);
|
||||||
|
|
||||||
int emptyId = 0;
|
QStringList list(tr("Not Present"));
|
||||||
QString columnName;
|
|
||||||
QStringList list(tr("Not present in CSV file"));
|
|
||||||
|
|
||||||
for (int i = 1; i < m_parserModel->getCsvCols(); ++i) {
|
for (int i = 1; i < m_parserModel->getCsvCols(); ++i) {
|
||||||
if (m_ui->checkBoxFieldNames->isChecked()) {
|
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()) {
|
if (columnName.isEmpty()) {
|
||||||
columnName = "<" + tr("Empty fieldname %1").arg(++emptyId) + ">";
|
list << QString(tr("Column %1").arg(i));
|
||||||
|
} else {
|
||||||
|
list << columnName;
|
||||||
}
|
}
|
||||||
list << columnName;
|
|
||||||
} else {
|
} else {
|
||||||
list << QString(tr("column %1").arg(i));
|
list << QString(tr("Column %1").arg(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_comboModel->setStringList(list);
|
m_comboModel->setStringList(list);
|
||||||
@@ -221,7 +174,6 @@ void CsvImportWidget::parse()
|
|||||||
} else {
|
} else {
|
||||||
m_ui->messageWidget->setHidden(true);
|
m_ui->messageWidget->setHidden(true);
|
||||||
}
|
}
|
||||||
QWidget::adjustSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CsvImportWidget::formatStatusText() const
|
QString CsvImportWidget::formatStatusText() const
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void parse();
|
void parse();
|
||||||
void comboChanged(QComboBox* currentSender, int comboId);
|
void comboChanged(int index);
|
||||||
void skippedChanged(int rows);
|
void skippedChanged(int rows);
|
||||||
void writeDatabase();
|
void writeDatabase();
|
||||||
void updatePreview();
|
void updatePreview();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user