Improve coding style in MainWindow::insertFields()
* Get rid of the unused variable * Fix typo
This commit is contained in:
parent
ce7595fd8a
commit
5e3a47f81d
|
@ -676,24 +676,28 @@ QString MainWindow::selectedFieldsString() const
|
||||||
*/
|
*/
|
||||||
void MainWindow::insertFields(const QString &fieldsString)
|
void MainWindow::insertFields(const QString &fieldsString)
|
||||||
{
|
{
|
||||||
const QModelIndexList selectedIndexes(m_ui->tableView->selectionModel()->selectedIndexes());
|
const auto selectedIndexes(m_ui->tableView->selectionModel()->selectedIndexes());
|
||||||
if (selectedIndexes.size() != 1) {
|
if (selectedIndexes.size() != 1) {
|
||||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Exactly one fields needs to be selected (top-left corner for insertion)."));
|
QMessageBox::warning(this, QApplication::applicationName(), tr("Exactly one field needs to be selected (top-left corner for insertion)."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rows = m_fieldModel->rowCount(), cols = m_fieldModel->columnCount();
|
const auto cols = m_fieldModel->columnCount();
|
||||||
int row = selectedIndexes.front().row();
|
const auto initCol = selectedIndexes.front().column();
|
||||||
int initCol = selectedIndexes.front().column();
|
const auto rowValues = [&] {
|
||||||
assert(row < rows);
|
QStringList lines = fieldsString.split('\n');
|
||||||
QStringList rowValues = fieldsString.split('\n');
|
if (lines.back().isEmpty()) {
|
||||||
if (rowValues.back().isEmpty()) {
|
lines.pop_back();
|
||||||
rowValues.pop_back();
|
}
|
||||||
}
|
return lines;
|
||||||
|
}();
|
||||||
|
|
||||||
|
auto row = selectedIndexes.front().row();
|
||||||
m_fieldModel->insertRows(row, rowValues.size(), QModelIndex());
|
m_fieldModel->insertRows(row, rowValues.size(), QModelIndex());
|
||||||
for (const QString &rowValue : rowValues) {
|
|
||||||
|
for (const auto &rowValue : rowValues) {
|
||||||
int col = initCol;
|
int col = initCol;
|
||||||
for (const QString &cellValue : rowValue.split('\t')) {
|
for (const auto &cellValue : rowValue.split('\t')) {
|
||||||
if (col < cols) {
|
if (col < cols) {
|
||||||
m_fieldModel->setData(m_fieldModel->index(row, col), cellValue, Qt::EditRole);
|
m_fieldModel->setData(m_fieldModel->index(row, col), cellValue, Qt::EditRole);
|
||||||
++col;
|
++col;
|
||||||
|
|
Loading…
Reference in New Issue