Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportDesign.cpp
Show All 24 Lines | |||||
25 | #include "KReportPluginManager.h" | 25 | #include "KReportPluginManager.h" | ||
26 | #include "KReportPluginInterface.h" | 26 | #include "KReportPluginInterface.h" | ||
27 | 27 | | |||
28 | #include <QDomDocument> | 28 | #include <QDomDocument> | ||
29 | #include <QDomElement> | 29 | #include <QDomElement> | ||
30 | #include <QPrinter> | 30 | #include <QPrinter> | ||
31 | #include <QPrinterInfo> | 31 | #include <QPrinterInfo> | ||
32 | 32 | | |||
33 | KReportDesignReadingStatus::KReportDesignReadingStatus() | 33 | class Q_DECL_HIDDEN KReportDesignReadingStatus::Private | ||
staniek: +Q_DECL_HIDDEN | |||||
34 | : lineNumber(-1), columnNumber(-1) | | |||
35 | { | 34 | { | ||
35 | public: | ||||
36 | QString errorMessage; | ||||
staniek: How about moving these docs to KReportDesign.h for the users? | |||||
37 | QString errorDetails; | ||||
38 | int errorLineNumber = -1; | ||||
39 | int errorColumnNumber = -1; | ||||
40 | }; | ||||
41 | | ||||
42 | KReportDesignReadingStatus::KReportDesignReadingStatus() : d(new Private) | ||||
43 | { | ||||
staniek: -> errorLineNumber | |||||
44 | } | ||||
45 | | ||||
46 | KReportDesignReadingStatus::~KReportDesignReadingStatus() | ||||
staniek: -> errorColumnNumber | |||||
47 | { | ||||
48 | delete d; | ||||
36 | } | 49 | } | ||
staniek: Minor, for the future: it's enough to use `new Private` without `()` | |||||
37 | 50 | | |||
51 | KReportDesignReadingStatus::KReportDesignReadingStatus(const KReportDesignReadingStatus& other) : d(new Private) | ||||
52 | { | ||||
53 | *this = other; | ||||
staniek: It's enough to call `*this = other` | |||||
54 | } | ||||
55 | | ||||
56 | KReportDesignReadingStatus& KReportDesignReadingStatus::operator=(const KReportDesignReadingStatus &other) | ||||
57 | { | ||||
58 | if (this != &other) { | ||||
59 | setErrorMessage(other.errorMessage()); | ||||
60 | setErrorDetails(other.errorDetails()); | ||||
61 | setErrorLineNumber(other.errorLineNumber()); | ||||
62 | setErrorColumnNumber(other.errorColumnNumber()); | ||||
63 | } | ||||
64 | | ||||
65 | return *this; | ||||
66 | } | ||||
67 | | ||||
68 | | ||||
38 | bool KReportDesignReadingStatus::isError() const | 69 | bool KReportDesignReadingStatus::isError() const | ||
39 | { | 70 | { | ||
40 | return lineNumber >= 0; | 71 | return d->errorLineNumber >= 0 && d->errorColumnNumber >= 0; | ||
72 | } | ||||
73 | | ||||
74 | int KReportDesignReadingStatus::errorColumnNumber() const | ||||
75 | { | ||||
76 | return d->errorColumnNumber; | ||||
77 | } | ||||
78 | | ||||
79 | QString KReportDesignReadingStatus::errorDetails() const | ||||
80 | { | ||||
81 | return d->errorDetails; | ||||
82 | } | ||||
83 | | ||||
84 | QString KReportDesignReadingStatus::errorMessage() const | ||||
85 | { | ||||
86 | return d->errorMessage; | ||||
87 | } | ||||
88 | | ||||
89 | | ||||
90 | int KReportDesignReadingStatus::errorLineNumber() const | ||||
91 | { | ||||
92 | return d->errorLineNumber; | ||||
93 | } | ||||
94 | | ||||
95 | void KReportDesignReadingStatus::setErrorColumnNumber(int column) | ||||
96 | { | ||||
97 | d->errorColumnNumber = column; | ||||
98 | } | ||||
99 | | ||||
100 | void KReportDesignReadingStatus::setErrorDetails(const QString& details) | ||||
101 | { | ||||
102 | d->errorDetails = details; | ||||
103 | } | ||||
104 | | ||||
105 | void KReportDesignReadingStatus::setErrorLineNumber(int line) | ||||
106 | { | ||||
107 | d->errorLineNumber = line; | ||||
108 | } | ||||
109 | | ||||
110 | void KReportDesignReadingStatus::setErrorMessage(const QString& msg) | ||||
111 | { | ||||
112 | d->errorMessage = msg; | ||||
staniek: missing `&& d->errorColumnNumber >= 0` | |||||
41 | } | 113 | } | ||
42 | 114 | | |||
43 | QDebug operator<<(QDebug dbg, const KReportDesignReadingStatus& status) | 115 | QDebug operator<<(QDebug dbg, const KReportDesignReadingStatus& status) | ||
44 | { | 116 | { | ||
45 | if (status.isError()) { | 117 | if (status.isError()) { | ||
46 | dbg.nospace() << qPrintable( | 118 | dbg.nospace() << qPrintable( | ||
47 | QString::fromLatin1("KReportDesignReadingStatus: errorMessage=\"%1\" " | 119 | QString::fromLatin1("KReportDesignReadingStatus: errorMessage=\"%1\" " | ||
48 | "errorDetails=\"%2\" line=%3 column=%4") | 120 | "errorDetails=\"%2\" line=%3 column=%4") | ||
49 | .arg(status.errorMessage).arg(status.errorDetails) | 121 | .arg(status.errorMessage()).arg(status.errorDetails()) | ||
50 | .arg(status.lineNumber).arg(status.columnNumber)); | 122 | .arg(status.errorLineNumber()).arg(status.errorColumnNumber())); | ||
51 | } else { | 123 | } else { | ||
52 | dbg.nospace() << "KReportDesignReadingStatus: OK"; | 124 | dbg.nospace() << "KReportDesignReadingStatus: OK"; | ||
53 | } | 125 | } | ||
54 | return dbg.space(); | 126 | return dbg.space(); | ||
55 | } | 127 | } | ||
56 | 128 | | |||
57 | //----------------------------------- | 129 | //----------------------------------- | ||
58 | 130 | | |||
59 | KReportDesign::KReportDesign() | 131 | KReportDesign::KReportDesign() | ||
60 | : d(new Private(this)) | 132 | : d(new Private(this)) | ||
61 | { | 133 | { | ||
62 | } | 134 | } | ||
63 | 135 | | |||
64 | KReportDesign::~KReportDesign() | 136 | KReportDesign::~KReportDesign() | ||
65 | { | 137 | { | ||
66 | delete d; | 138 | delete d; | ||
67 | } | 139 | } | ||
68 | 140 | | |||
69 | bool KReportDesign::setContent(const QString &text, KReportDesignReadingStatus *status) | 141 | bool KReportDesign::setContent(const QString &text, KReportDesignReadingStatus *status) | ||
70 | { | 142 | { | ||
71 | QDomDocument doc; | 143 | QDomDocument doc; | ||
72 | if (!doc.setContent(text, status ? &status->errorDetails : 0, status ? &status->lineNumber : 0, | 144 | QString errorDetails; | ||
73 | status ? &status->columnNumber : 0)) | 145 | int errorLine; | ||
146 | int errorColumn; | ||||
147 | | ||||
148 | if (!doc.setContent(text, &errorDetails, &errorLine, &errorColumn)) | ||||
74 | { | 149 | { | ||
75 | if (status) { | 150 | if (status) { | ||
76 | status->errorMessage = tr("Could not parse XML document."); | 151 | status->setErrorMessage(tr("Could not parse XML document.")); | ||
152 | status->setErrorDetails(errorDetails); | ||||
153 | status->setErrorLineNumber(errorLine); | ||||
154 | status->setErrorColumnNumber(errorColumn); | ||||
77 | } | 155 | } | ||
78 | return false; | 156 | return false; | ||
79 | } | 157 | } | ||
80 | return d->processDocument(doc, status); | 158 | bool ret = d->processDocument(doc, status); | ||
159 | if (!ret && status) { | ||||
160 | status->setErrorMessage(tr("Error in XML document.")); | ||||
staniek: if (status) { .. } | |||||
161 | } | ||||
162 | return ret; | ||||
Unrelated to the port but while we're at this: we're not setting message at all here or removing previous one. Note that the status object is supplied by the user so we don't know what it is. Proposed solution: if d->processDocument(doc, status) fails, set error message to something like tr("Error in XML document."). staniek: Unrelated to the port but while we're at this: we're not setting message at all here or… | |||||
81 | } | 163 | } | ||
82 | 164 | | |||
83 | QString KReportDesign::toString(int indent) const | 165 | QString KReportDesign::toString(int indent) const | ||
84 | { | 166 | { | ||
85 | Q_UNUSED(indent); | 167 | Q_UNUSED(indent); | ||
86 | //! @todo | 168 | //! @todo | ||
87 | return QString(); | 169 | return QString(); | ||
88 | } | 170 | } | ||
Show All 21 Lines | |||||
110 | 192 | | |||
111 | KReportElement KReportDesign::createElement(const QString &typeName, QString *errorMessage) | 193 | KReportElement KReportDesign::createElement(const QString &typeName, QString *errorMessage) | ||
112 | { | 194 | { | ||
113 | QDomElement el; | 195 | QDomElement el; | ||
114 | KReportDesignReadingStatus status; | 196 | KReportDesignReadingStatus status; | ||
115 | KReportPluginInterface* plugin = d->findPlugin(typeName, el, &status); | 197 | KReportPluginInterface* plugin = d->findPlugin(typeName, el, &status); | ||
116 | if (!plugin) { | 198 | if (!plugin) { | ||
117 | if (errorMessage) { | 199 | if (errorMessage) { | ||
118 | *errorMessage = status.errorMessage; | 200 | *errorMessage = status.errorMessage(); | ||
119 | } | 201 | } | ||
120 | return KReportElement(); | 202 | return KReportElement(); | ||
121 | } | 203 | } | ||
122 | return plugin->createElement(); | 204 | return plugin->createElement(); | ||
123 | } | 205 | } | ||
124 | 206 | | |||
125 | bool KReportDesign::hasSection(KReportSection::Type type) const | 207 | bool KReportDesign::hasSection(KReportSection::Type type) const | ||
126 | { | 208 | { | ||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |
+Q_DECL_HIDDEN