Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/mymoney/mymoneycostcenter.cpp
Show All 14 Lines | |||||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "mymoneycostcenter.h" | 18 | #include "mymoneycostcenter.h" | ||
19 | 19 | | |||
20 | // ---------------------------------------------------------------------------- | 20 | // ---------------------------------------------------------------------------- | ||
21 | // QT Includes | 21 | // QT Includes | ||
22 | 22 | | |||
23 | #include <QDomElement> | | |||
24 | #include <QCollator> | 23 | #include <QCollator> | ||
25 | 24 | | |||
26 | // ---------------------------------------------------------------------------- | 25 | // ---------------------------------------------------------------------------- | ||
27 | // Project Includes | 26 | // Project Includes | ||
28 | 27 | | |||
29 | #include "mymoneyobject_p.h" | 28 | #include "mymoneyobject_p.h" | ||
30 | #include "mymoneyexception.h" | 29 | #include "mymoneyexception.h" | ||
31 | #include "mymoneystoragenames.h" | 30 | #include "mymoneystoragenames.h" | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
75 | bool MyMoneyCostCenter::operator < (const MyMoneyCostCenter& right) const | 74 | bool MyMoneyCostCenter::operator < (const MyMoneyCostCenter& right) const | ||
76 | { | 75 | { | ||
77 | Q_D(const MyMoneyCostCenter); | 76 | Q_D(const MyMoneyCostCenter); | ||
78 | auto d2 = static_cast<const MyMoneyCostCenterPrivate *>(right.d_func()); | 77 | auto d2 = static_cast<const MyMoneyCostCenterPrivate *>(right.d_func()); | ||
79 | QCollator col; | 78 | QCollator col; | ||
80 | return col.compare(d->m_name, d2->m_name); | 79 | return col.compare(d->m_name, d2->m_name); | ||
81 | } | 80 | } | ||
82 | 81 | | |||
83 | void MyMoneyCostCenter::writeXML(QDomDocument& document, QDomElement& parent) const | | |||
84 | { | | |||
85 | auto el = document.createElement(nodeNames[nnCostCenter]); | | |||
86 | | ||||
87 | Q_D(const MyMoneyCostCenter); | | |||
88 | d->writeBaseXML(document, el); | | |||
89 | | ||||
90 | el.setAttribute(getAttrName(Attribute::Name), d->m_name); | | |||
91 | parent.appendChild(el); | | |||
92 | } | | |||
93 | | ||||
94 | bool MyMoneyCostCenter::hasReferenceTo(const QString& /*id*/) const | 82 | bool MyMoneyCostCenter::hasReferenceTo(const QString& /*id*/) const | ||
95 | { | 83 | { | ||
96 | return false; | 84 | return false; | ||
97 | } | 85 | } | ||
98 | 86 | | |||
99 | QString MyMoneyCostCenter::name() const | 87 | QString MyMoneyCostCenter::name() const | ||
100 | { | 88 | { | ||
101 | Q_D(const MyMoneyCostCenter); | 89 | Q_D(const MyMoneyCostCenter); | ||
Show All 11 Lines | |||||
113 | { | 101 | { | ||
114 | Q_D(const MyMoneyCostCenter); | 102 | Q_D(const MyMoneyCostCenter); | ||
115 | QRegExp shortNumberExp("^(\\d+)\\s.+"); | 103 | QRegExp shortNumberExp("^(\\d+)\\s.+"); | ||
116 | if(shortNumberExp.exactMatch(d->m_name)) { | 104 | if(shortNumberExp.exactMatch(d->m_name)) { | ||
117 | return shortNumberExp.cap(1); | 105 | return shortNumberExp.cap(1); | ||
118 | } | 106 | } | ||
119 | return d->m_name; | 107 | return d->m_name; | ||
120 | } | 108 | } | ||
121 | | ||||
122 | QString MyMoneyCostCenter::getAttrName(const Attribute attr) | | |||
123 | { | | |||
124 | static const QMap<Attribute, QString> attrNames = { | | |||
125 | {Attribute::Name, QStringLiteral("name")}, | | |||
126 | }; | | |||
127 | return attrNames[attr]; | | |||
128 | } | |