[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kmymoney] kmymoney: Port date editor related kf5 TODOs.
From:       Cristian_OneČ› <onet.cristian () gmail ! com>
Date:       2016-06-23 8:46:25
Message-ID: E1bG0HJ-00089a-CX () code ! kde ! org
[Download RAW message or body]

Git commit 82168a85a03521b41048341cb9de9658f394a84a by Cristian OneČ›.
Committed on 23/06/2016 at 08:36.
Pushed by conet into branch 'master'.

Port date editor related kf5 TODOs.

Since we are using QLocale now the code which was translation from
posix date format (using %) to Qt date format is no longer relevant
so that was dropped. This means that it might not make sense to keep
KMyMoneyDateEdit class anymore.

M  +3    -4    kmymoney/reports/tests/pivottable-test.cpp
M  +1    -2    kmymoney/views/newtransactioneditor.cpp
M  +0    -42   kmymoney/widgets/kmymoneydateedit.cpp
M  +1    -4    kmymoney/widgets/kmymoneydateedit.h
M  +1    -38   kmymoney/widgets/kmymoneydateinput.cpp

http://commits.kde.org/kmymoney/82168a85a03521b41048341cb9de9658f394a84a

diff --git a/kmymoney/reports/tests/pivottable-test.cpp \
b/kmymoney/reports/tests/pivottable-test.cpp index 6d48e14..aa753bc 100644
--- a/kmymoney/reports/tests/pivottable-test.cpp
+++ b/kmymoney/reports/tests/pivottable-test.cpp
@@ -20,6 +20,7 @@
 #include <QList>
 #include <QFile>
 #include <QTest>
+#include <QTextCodec>
 
 // DOH, mmreport.h uses this without including it!!
 #include "mymoneyaccount.h"
@@ -1011,9 +1012,8 @@ void PivotTableTest::testHtmlEncoding()
   filter.setDateFilter(QDate(2004, 1, 1), QDate(2005, 1, 1).addDays(-1));
   XMLandback(filter);
   PivotTable networth_f(filter);
-  // TODO: port to kf5
-#if 0
-  QByteArray encoding = KLocale::global()->encoding();
+
+  QByteArray encoding = QTextCodec::codecForLocale()->name();
 
   QString html = networth_f.renderHTML(0, encoding, filter.name(), false);
 
@@ -1021,5 +1021,4 @@ void PivotTableTest::testHtmlEncoding()
   rx.setPatternSyntax(QRegExp::Wildcard);
   rx.setCaseSensitivity(Qt::CaseInsensitive);
   QVERIFY(rx.exactMatch(html));
-#endif
 }
diff --git a/kmymoney/views/newtransactioneditor.cpp \
b/kmymoney/views/newtransactioneditor.cpp index ee6dfdc..6b9b16c 100644
--- a/kmymoney/views/newtransactioneditor.cpp
+++ b/kmymoney/views/newtransactioneditor.cpp
@@ -302,8 +302,7 @@ NewTransactionEditor::NewTransactionEditor(QWidget* parent, const \
QString& accou  
   d->ui->statusCombo->setModel(&d->statusModel);
 
-  // TODO: port to kf5
-  //d->ui->dateEdit->setDateFormat(KLocale::global()->dateFormatShort());
+  d->ui->dateEdit->setDisplayFormat(QLocale().dateFormat(QLocale::ShortFormat));
 
   WidgetHintFrameCollection* frameCollection = new WidgetHintFrameCollection(this);
   frameCollection->addFrame(new WidgetHintFrame(d->ui->dateEdit));
diff --git a/kmymoney/widgets/kmymoneydateedit.cpp \
b/kmymoney/widgets/kmymoneydateedit.cpp index cff3085..acdbe32 100644
--- a/kmymoney/widgets/kmymoneydateedit.cpp
+++ b/kmymoney/widgets/kmymoneydateedit.cpp
@@ -34,45 +34,3 @@ KMyMoneyDateEdit::KMyMoneyDateEdit(QWidget* parent)
   : QDateEdit(parent)
 {
 }
-
-void KMyMoneyDateEdit::setDateFormat(const QString& dateFormat)
-{
-  QString format = dateFormat.toLower();
-  QString order, separator;
-  bool lastWasPercent = false;
-  for (int i = 0; i < format.length(); ++i) {
-    // DD.MM.YYYY is %d.%m.%y
-    // dD.mM.YYYY is %e.%n.%y
-    // SHORTWEEKDAY, dD SHORTMONTH YYYY is %a, %e %b %Y
-    if (lastWasPercent == true) {
-      if (format[i] == 'y' || format[i] == 'm' || format[i] == 'n' || format[i] == \
                'd' || format[i] == 'e') {
-        if (format[i] == 'n')
-          format[i] = 'm';
-        if (format[i] == 'e')
-          format[i] = 'd';
-        order += format[i];
-      }
-
-    } else if (format[i] == '%') {
-      lastWasPercent = true;
-      continue;
-
-    } else if (separator.isEmpty() && !order.isEmpty())
-      separator = format[i];
-
-    if (order.length() == 3)
-      break;
-    lastWasPercent = false;
-  }
-
-  // see if we find a known format. If it's unknown, then we use YMD (international)
-  if (order == "mdy") {
-    setDisplayFormat(QString("MM%1dd%2yyyy").arg(separator, separator));
-  } else if (order == "dmy") {
-    setDisplayFormat(QString("dd%1MM%2yyyy").arg(separator, separator));
-  } else if (order == "ydm") {
-    setDisplayFormat(QString("yyyy%1dd%2MM").arg(separator, separator));
-  } else {
-    setDisplayFormat(QString("yyyy%1MM%2dd").arg(separator, separator));
-  }
-}
diff --git a/kmymoney/widgets/kmymoneydateedit.h \
b/kmymoney/widgets/kmymoneydateedit.h index 95b1679..b3789de 100644
--- a/kmymoney/widgets/kmymoneydateedit.h
+++ b/kmymoney/widgets/kmymoneydateedit.h
@@ -22,6 +22,7 @@
 
 #include <QDateEdit>
 
+// TODO: check if this class is really necessary
 class KMyMoneyDateEdit : public QDateEdit
 {
   Q_OBJECT
@@ -29,9 +30,5 @@ class KMyMoneyDateEdit : public QDateEdit
 public:
   explicit KMyMoneyDateEdit(QWidget* parent = 0);
 
-  void setDateFormat(const QString& dateFormat);
-
-private:
-  void init();
 };
 #endif // KMYMONEYDATEEDIT_H
diff --git a/kmymoney/widgets/kmymoneydateinput.cpp \
b/kmymoney/widgets/kmymoneydateinput.cpp index dfba408..cd39ff9 100644
--- a/kmymoney/widgets/kmymoneydateinput.cpp
+++ b/kmymoney/widgets/kmymoneydateinput.cpp
@@ -143,44 +143,7 @@ kMyMoneyDateInput::kMyMoneyDateInput(QWidget *parent, \
Qt::AlignmentFlag flags)  d->m_dateFrame->setWindowFlags(Qt::Popup);
   d->m_dateFrame->hide();
 
-  QString dateFormat = QLocale().dateFormat(QLocale::ShortFormat);
-  QString order, separator;
-  bool lastWasPercent = false;
-  for (int i = 0; i < dateFormat.length(); ++i) {
-    // DD.MM.YYYY is %d.%m.%y
-    // dD.mM.YYYY is %e.%n.%y
-    // SHORTWEEKDAY, dD SHORTMONTH YYYY is %a, %e %b %Y
-    if (lastWasPercent == true) {
-      if (dateFormat[i] == 'y' || dateFormat[i] == 'm' || dateFormat[i] == 'n' || \
                dateFormat[i] == 'd' || dateFormat[i] == 'e') {
-        if (dateFormat[i] == 'n')
-          dateFormat[i] = 'm';
-        if (dateFormat[i] == 'e')
-          dateFormat[i] = 'd';
-        order += dateFormat[i];
-      }
-
-    } else if (dateFormat[i] == '%') {
-      lastWasPercent = true;
-      continue;
-
-    } else if (separator.isEmpty() && !order.isEmpty())
-      separator = dateFormat[i];
-
-    if (order.length() == 3)
-      break;
-    lastWasPercent = false;
-  }
-
-  // see if we find a known format. If it's unknown, then we use YMD (international)
-  if (order == "mdy") {
-    d->m_dateEdit->setDisplayFormat(QString("MM%1dd%2yyyy").arg(separator, \
                separator));
-  } else if (order == "dmy") {
-    d->m_dateEdit->setDisplayFormat(QString("dd%1MM%2yyyy").arg(separator, \
                separator));
-  } else if (order == "ydm") {
-    d->m_dateEdit->setDisplayFormat(QString("yyyy%1dd%2MM").arg(separator, \
                separator));
-  } else {
-    d->m_dateEdit->setDisplayFormat(QString("yyyy%1MM%2dd").arg(separator, \
                separator));
-  }
+  d->m_dateEdit->setDisplayFormat(QLocale().dateFormat(QLocale::ShortFormat));
 
   d->m_datePicker = new KDatePicker(d->m_date, d->m_dateFrame);
   dateFrameVBoxLayout->addWidget(d->m_datePicker);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic