[kmymoney/5.0] kmymoney/plugins/csv/import: Improve memo column selection in CSV import wizard

Thomas Baumgart null at kde.org
Sun Feb 10 11:39:45 GMT 2019


Git commit cc119c58deaf77ead758e3b3ae729663f9362a78 by Thomas Baumgart.
Committed on 10/02/2019 at 11:19.
Pushed by tbaumgart into branch '5.0'.

Improve memo column selection in CSV import wizard

The CSV import wizard did allow to select multiple columns for memo
fields but it was not visible to the user which ones were selected.
Also, there is no way to clear the memo selection only but only all
column assignments.

This change adds a display item that shows the selected columns and also
adds a clear button to clear the memo field selection only.

GUI:
BUG: 404156
FIXED-IN: 5.0.4

M  +53   -19   kmymoney/plugins/csv/import/bankingwizardpage.cpp
M  +3    -1    kmymoney/plugins/csv/import/bankingwizardpage.h
M  +73   -51   kmymoney/plugins/csv/import/bankingwizardpage.ui

https://commits.kde.org/kmymoney/cc119c58deaf77ead758e3b3ae729663f9362a78

diff --git a/kmymoney/plugins/csv/import/bankingwizardpage.cpp b/kmymoney/plugins/csv/import/bankingwizardpage.cpp
index 26f7a6982..236cb13a1 100644
--- a/kmymoney/plugins/csv/import/bankingwizardpage.cpp
+++ b/kmymoney/plugins/csv/import/bankingwizardpage.cpp
@@ -63,14 +63,19 @@ BankingPage::BankingPage(CSVWizard *dlg, CSVImporterCore *imp) :
 
   m_profile = dynamic_cast<BankingProfile *>(m_imp->m_profile);
 
-  connect(ui->m_amountCol, SIGNAL(currentIndexChanged(int)), this, SLOT(amountColSelected(int)));
-  connect(ui->m_debitCol, SIGNAL(currentIndexChanged(int)), this, SLOT(debitColSelected(int)));
-  connect(ui->m_creditCol, SIGNAL(currentIndexChanged(int)), this, SLOT(creditColSelected(int)));
-  connect(ui->m_memoCol, SIGNAL(currentIndexChanged(int)), this, SLOT(memoColSelected(int)));
-  connect(ui->m_numberCol, SIGNAL(currentIndexChanged(int)), this, SLOT(numberColSelected(int)));
-  connect(ui->m_dateCol, SIGNAL(currentIndexChanged(int)), this, SLOT(dateColSelected(int)));
-  connect(ui->m_payeeCol, SIGNAL(currentIndexChanged(int)), this, SLOT(payeeColSelected(int)));
-  connect(ui->m_categoryCol, SIGNAL(currentIndexChanged(int)), this, SLOT(categoryColSelected(int)));
+  void (QComboBox::* signal)(int) = &QComboBox::currentIndexChanged;
+  connect(ui->m_amountCol, signal, this, &BankingPage::amountColSelected);
+  connect(ui->m_debitCol, signal, this, &BankingPage::debitColSelected);
+  connect(ui->m_creditCol, signal, this, &BankingPage::creditColSelected);
+  connect(ui->m_memoCol, signal, this, &BankingPage::memoColSelected);
+  connect(ui->m_numberCol, signal, this, &BankingPage::numberColSelected);
+  connect(ui->m_dateCol, signal, this, &BankingPage::dateColSelected);
+  connect(ui->m_payeeCol, signal, this, &BankingPage::payeeColSelected);
+  connect(ui->m_categoryCol, signal, this, &BankingPage::categoryColSelected);
+
+  connect(ui->m_clearMemoColumns, &QToolButton::clicked, this, &BankingPage::clearMemoColumns);
+
+  updateCurrentMemoSelection();
 }
 
 BankingPage::~BankingPage()
@@ -89,8 +94,9 @@ void BankingPage::initializePage()
     m_dlg->initializeComboBoxes(columns);
 
   columns.remove(Column::Memo);
-  for (auto it = columns.cbegin(); it != columns.cend(); ++it)
+  for (auto it = columns.cbegin(); it != columns.cend(); ++it) {
     it.value()->setCurrentIndex(m_profile->m_colTypeNum.value(it.key()));
+  }
 
   ui->m_oppositeSigns->setChecked(m_profile->m_oppositeSigns);
 
@@ -123,11 +129,12 @@ bool BankingPage::isComplete() const
 
 bool BankingPage::validateMemoComboBox()
 {
-  if (m_profile->m_memoColList.count() == 0)
+  if (m_profile->m_memoColList.isEmpty())
     return true;
+
   for (int i = 0; i < ui->m_memoCol->count(); ++i)
   {
-    QString txt = ui->m_memoCol->itemText(i);
+    const QString txt = ui->m_memoCol->itemText(i);
     if (txt.contains(QLatin1Char('*')))  // check if text containing '*' belongs to valid column types
       if (m_profile->m_colNumType.value(i) != Column::Payee) {
         ui->m_memoCol->setItemText(i, QString::number(i + 1));
@@ -161,17 +168,38 @@ void BankingPage::memoColSelected(int col)
     else
       ui->m_memoCol->setCurrentIndex(-1);
     ui->m_memoCol->blockSignals(false);
-    return;
+
+  } else {
+    if (m_profile->m_colTypeNum.value(Column::Memo) != -1)        // check if this memo has any column 'number' assigned...
+      m_profile->m_memoColList.removeOne(col);           // ...if true remove it from memo list
+
+    if(validateSelectedColumn(col, Column::Memo)) {
+      if (col != - 1 && !m_profile->m_memoColList.contains(col)) {
+        m_profile->m_memoColList.append(col);
+        qSort(m_profile->m_memoColList);
+      }
+    }
   }
+  updateCurrentMemoSelection();
+}
 
-  if (m_profile->m_colTypeNum.value(Column::Memo) != -1)        // check if this memo has any column 'number' assigned...
-    m_profile->m_memoColList.removeOne(col);           // ...if true remove it from memo list
+void BankingPage::updateCurrentMemoSelection()
+{
+  const auto& list = m_profile->m_memoColList;
+  const bool haveSelection = !list.isEmpty();
+  QString txt;
+  if (haveSelection) {
+    for (const auto& entry : list) {
+      txt += QString("%1, ").arg(entry+1);
+    }
+    txt = txt.left(txt.length()-2);
+  }
+  ui->m_currentMemoColums->setText(QString("%1").arg(txt, -30, QChar(' ')));
 
-  if(validateSelectedColumn(col, Column::Memo))
-    if (col != - 1 && !m_profile->m_memoColList.contains(col))
-      m_profile->m_memoColList.append(col);
+  ui->m_clearMemoColumns->setEnabled(haveSelection);
 }
 
+
 void BankingPage::categoryColSelected(int col)
 {
   validateSelectedColumn(col, Column::Category);
@@ -185,7 +213,7 @@ void BankingPage::numberColSelected(int col)
 void BankingPage::payeeColSelected(int col)
 {
   if (validateSelectedColumn(col, Column::Payee))
-    if (!validateMemoComboBox())  // user could have it already in memo so...
+    if (!validateMemoComboBox() && col != -1)  // user could have it already in memo so...
       memoColSelected(col);    // ...if true set memo field again
 }
 
@@ -247,12 +275,18 @@ void BankingPage::clearColumns()
 {
   ui->m_dateCol->setCurrentIndex(-1);
   ui->m_payeeCol->setCurrentIndex(-1);
-  ui->m_memoCol->setCurrentIndex(-1);
   ui->m_numberCol->setCurrentIndex(-1);
   ui->m_amountCol->setCurrentIndex(-1);
   ui->m_debitCol->setCurrentIndex(-1);
   ui->m_creditCol->setCurrentIndex(-1);
   ui->m_categoryCol->setCurrentIndex(-1);
+  clearMemoColumns();
+}
+
+void BankingPage::clearMemoColumns()
+{
+  m_profile->m_memoColList.clear();
+  ui->m_memoCol->setCurrentIndex(-1);
 }
 
 void BankingPage::resetComboBox(const Column comboBox)
diff --git a/kmymoney/plugins/csv/import/bankingwizardpage.h b/kmymoney/plugins/csv/import/bankingwizardpage.h
index 43f664349..7297e0e96 100644
--- a/kmymoney/plugins/csv/import/bankingwizardpage.h
+++ b/kmymoney/plugins/csv/import/bankingwizardpage.h
@@ -66,7 +66,6 @@ private:
   BankingProfile       *m_profile;
   Ui::BankingPage      *ui;
 
-private Q_SLOTS:
   void                memoColSelected(int col);
   void                categoryColSelected(int col);
   void                numberColSelected(int col);
@@ -79,6 +78,9 @@ private Q_SLOTS:
   void                debitCreditToggled(bool checked);
   void                oppositeSignsClicked(bool checked);
   void                clearColumns();
+  void                updateCurrentMemoSelection();
+  void                clearMemoColumns();
+
 };
 
 #endif // BANKINGWIZARDPAGE_H
diff --git a/kmymoney/plugins/csv/import/bankingwizardpage.ui b/kmymoney/plugins/csv/import/bankingwizardpage.ui
index 8e01e25a3..4a781dc77 100644
--- a/kmymoney/plugins/csv/import/bankingwizardpage.ui
+++ b/kmymoney/plugins/csv/import/bankingwizardpage.ui
@@ -19,7 +19,7 @@
   <property name="windowTitle">
    <string>Banking Wizard Page</string>
   </property>
-  <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,10,1">
+  <layout class="QHBoxLayout" name="horizontalLayout" stretch="5,1,5">
    <item>
     <spacer name="leftSpacer">
      <property name="orientation">
@@ -56,7 +56,7 @@
       </widget>
      </item>
      <item>
-      <layout class="QGridLayout" name="gridLayout" columnstretch="0,5,0,0,0,5,5">
+      <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,0,0,0">
        <item row="3" column="4">
         <widget class="QLabel" name="labelBnk_debits">
          <property name="enabled">
@@ -244,22 +244,6 @@
          </property>
         </widget>
        </item>
-       <item row="4" column="6">
-        <widget class="QPushButton" name="m_clear">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="toolTip">
-          <string>Clear selected column entries</string>
-         </property>
-         <property name="text">
-          <string>Clear</string>
-         </property>
-        </widget>
-       </item>
        <item row="4" column="0">
         <widget class="QLabel" name="labelBnk_payee">
          <property name="accessibleName">
@@ -274,20 +258,41 @@
         </widget>
        </item>
        <item row="6" column="1">
-        <widget class="QComboBox" name="m_memoCol">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="toolTip">
-          <string>Select column containing memo field.</string>
-         </property>
-         <property name="maxVisibleItems">
-          <number>12</number>
-         </property>
-        </widget>
+        <layout class="QHBoxLayout" name="horizontalLayout" stretch="1,10,0">
+         <item>
+          <widget class="QComboBox" name="m_memoCol">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
+           <property name="toolTip">
+            <string>Select column containing memo field.</string>
+           </property>
+           <property name="maxVisibleItems">
+            <number>12</number>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QLabel" name="m_currentMemoColums">
+           <property name="text">
+            <string notr="true">Selection</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QToolButton" name="m_clearMemoColumns">
+           <property name="toolTip">
+            <string>Clear selected memo column entries</string>
+           </property>
+           <property name="text">
+            <string comment="Clear memo column assignment">Clear</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
        </item>
        <item row="4" column="1">
         <widget class="QComboBox" name="m_payeeCol">
@@ -318,25 +323,6 @@
          </property>
         </widget>
        </item>
-       <item row="6" column="3">
-        <widget class="QCheckBox" name="m_oppositeSigns">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="toolTip">
-          <string>Select if your amount column has signs improperly set.</string>
-         </property>
-         <property name="layoutDirection">
-          <enum>Qt::LeftToRight</enum>
-         </property>
-         <property name="text">
-          <string>Opposite signs</string>
-         </property>
-        </widget>
-       </item>
        <item row="2" column="1">
         <widget class="QComboBox" name="m_numberCol">
          <property name="sizePolicy">
@@ -420,6 +406,41 @@
          </property>
         </widget>
        </item>
+       <item row="5" column="5">
+        <widget class="QCheckBox" name="m_oppositeSigns">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="toolTip">
+          <string>Select if your amount column has signs improperly set.</string>
+         </property>
+         <property name="layoutDirection">
+          <enum>Qt::LeftToRight</enum>
+         </property>
+         <property name="text">
+          <string>Opposite signs</string>
+         </property>
+        </widget>
+       </item>
+       <item row="7" column="5">
+        <widget class="QPushButton" name="m_clear">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="toolTip">
+          <string>Clear all selected column entries</string>
+         </property>
+         <property name="text">
+          <string comment="Clear all column assignments">Clear all</string>
+         </property>
+        </widget>
+       </item>
       </layout>
      </item>
     </layout>
@@ -445,6 +466,7 @@
   <tabstop>m_payeeCol</tabstop>
   <tabstop>m_categoryCol</tabstop>
   <tabstop>m_memoCol</tabstop>
+  <tabstop>m_clearMemoColumns</tabstop>
   <tabstop>m_radioAmount</tabstop>
   <tabstop>m_radioDebitCredit</tabstop>
   <tabstop>m_amountCol</tabstop>


More information about the kde-doc-english mailing list