Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
universaldata.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023-2024 QuasarApp.
3 * Distributed under the GPLv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#include "universaldata.h"
9
10
11namespace QH {
12namespace PKG {
13
18
19void UniversalData::setValue(int key, const QVariant &value) {
20 _data[key] = value;
21}
22
23const QVariant &UniversalData::value(int key, const QVariant &defaultVal) const {
24
25 auto nonConstPtr = const_cast<QHash<int, QVariant>*>(&_data);
26 if (!nonConstPtr)
27 return defaultVal;
28
29 if (nonConstPtr->contains(key)) {
30 return nonConstPtr->operator[](key);
31 }
32
33 return defaultVal;
34}
35
36QVariant *UniversalData::ref(int key) {
37
38 if (_data.contains(key)) {
39 return &_data.operator[](key);
40 }
41
42 return nullptr;
43}
44
45QDataStream &UniversalData::fromStream(QDataStream &stream) {
46
47 stream >> _data;
48
49 return stream;
50}
51
52QDataStream &UniversalData::toStream(QDataStream &stream) const {
53 stream << _data;
54
55 return stream;
56}
57}
58}
void setValue(int key, const QVariant &value)
setValue This method sets new value for the filed. Works like a insert method of the QMap
const QVariant & value(int key, const QVariant &defaultVal={}) const
value this method return value of the key.
QDataStream & toStream(QDataStream &stream) const override final
fromStream This method should be write all members of the current object to the stream object.
QDataStream & fromStream(QDataStream &stream) override final
fromStream This method should be read all bytes from the stream object and full the current object.
QVariant * ref(int key)
ref This method return pointer to the object If this object is not exists return nullptr
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13