Smithy Qt 0.1.0-pre
Internal development documentation
Loading...
Searching...
No Matches
ModelPrivate Class Reference

The ModelPrivate class provides private implementation for Model. More...

Collaboration diagram for ModelPrivate:
[legend]

Public Member Functions

 ModelPrivate (Model *const q)
 

Static Public Member Functions

static QJsonObject mergeMetadata (const QMultiHash< QString, QJsonValue > &metadata)
 
static QVersionNumber smithyVersion (const QJsonObject &ast)
 

Static Protected Member Functions

static Q_LOGGING_CATEGORY (lc, "smithy.Model", QtInfoMsg)
 Logging category for Model.
 

Protected Attributes

Modelq_ptr
 Internal q-pointer.
 

Private Member Functions

 Q_DECLARE_TR_FUNCTIONS (Model)
 

Private Attributes

Model::Error error
 
QMultiHash< QString, QJsonValue > allMetadata
 
QMultiHash< ShapeId, ShapeallShapes
 
QJsonObject mergedMetadata
 
QHash< ShapeId, ShapemergedShapes
 

Detailed Description

The ModelPrivate class provides private implementation for Model.

Definition at line 21 of file model_p.h.

Constructor & Destructor Documentation

◆ ModelPrivate()

ModelPrivate::ModelPrivate ( Model *const q)
explicit

Constructs a new ModelPrivate object with public implementation q.

Definition at line 257 of file model.cpp.

257 : q_ptr(q)
258{
259
260}
Model * q_ptr
Internal q-pointer.
Definition model_p.h:32

References q_ptr.

Member Function Documentation

◆ mergeMetadata()

QJsonObject ModelPrivate::mergeMetadata ( const QMultiHash< QString, QJsonValue > & metadata)
static

Definition at line 263 of file model.cpp.

264{
265 qCDebug(lc).noquote() << tr("Merging %n metedata entry(s)", nullptr, metadata.size());
266 QJsonObject merged;
267 const QStringList keys = metadata.keys();
268 for (const QString &key: keys) {
269 // If values are arrays, concatenate them.
270 const auto values = metadata.values(key);
271 if (values.first().isArray()) {
272 QJsonArray concatenatedArray;
273 for (const QJsonValue &value: values) {
274 if (!value.isArray()) {
275 qCCritical(lc).noquote() << tr("Metadata %1 has conflicting types").arg(key);
276 return QJsonObject{};
277 }
278 const QJsonArray thisArray = value.toArray();
279 for (const QJsonValue &item: thisArray) {
280 concatenatedArray.append(item);
281 }
282 }
283 merged.insert(key, concatenatedArray);
284 continue;
285 }
286
287 // Otherwise all values must be identical.
288 for (const QJsonValue &value: values) {
289 qDebug() << values.first() << value;
290 if (value != values.first()) {
291 qCDebug(lc).noquote() << tr("Metatadata %1 has conflicting values").arg(key);
292 return QJsonObject{};
293 }
294 }
295 merged.insert(key, values.first());
296 }
297 qCDebug(lc).noquote() << tr("Merged %n metedata entry(s) to %1", nullptr, metadata.size())
298 .arg(merged.size());
299 return merged;
300}

◆ smithyVersion()

QVersionNumber ModelPrivate::smithyVersion ( const QJsonObject & ast)
static

Definition at line 302 of file model.cpp.

303{
304 const QString versionString = ast.value(QLatin1String("smithy")).toString();
305 qCDebug(lc).noquote() << tr("Smithy version string:") << versionString;
306 #if (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))
307 int suffixIndex = -1; // Initial value is ignored.
308 #else
309 qsizetype suffixIndex = -1; // Initial value is ignored.
310 #endif
311 const QVersionNumber versionNumber = QVersionNumber::fromString(versionString, &suffixIndex);
312 qCDebug(lc).noquote() << tr("Smithy version number:") << versionNumber;
313 if (versionNumber.isNull()) {
314 qCWarning(lc).noquote() << tr("Failed to parse Smithy version \"%1\"").arg(versionString);
315 } else if (suffixIndex < versionString.length()) {
316 qCWarning(lc).noquote() << tr("Ignoring Smithy version suffix \"%1\"")
317 .arg(versionString.mid(suffixIndex));
318 }
319 return versionNumber;
320}

Member Data Documentation

◆ allMetadata

QMultiHash<QString, QJsonValue> ModelPrivate::allMetadata
private

Definition at line 37 of file model_p.h.

◆ allShapes

QMultiHash<ShapeId, Shape> ModelPrivate::allShapes
private

Definition at line 38 of file model_p.h.

◆ error

Model::Error ModelPrivate::error
private

Definition at line 36 of file model_p.h.

◆ mergedMetadata

QJsonObject ModelPrivate::mergedMetadata
private

Definition at line 39 of file model_p.h.

◆ mergedShapes

QHash<ShapeId, Shape> ModelPrivate::mergedShapes
private

Definition at line 40 of file model_p.h.

◆ q_ptr

Model* ModelPrivate::q_ptr
protected

Internal q-pointer.

Definition at line 32 of file model_p.h.

Referenced by ModelPrivate().


The documentation for this class was generated from the following files: