Skip to content

Commit

Permalink
Get ready for QIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
beckdave committed Apr 21, 2024
1 parent 3f4d306 commit 4538064
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 42 deletions.
33 changes: 31 additions & 2 deletions htdocs/qtobjecttree.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,44 @@
table += '<tr>';
table += '<td>' + prop.type + '</td>';
table += '<td>' + prop.name + '</td>';
var propertyValue = prop.value.substr(0, 100);

if (prop.type == 'QIcon')
{
var icon = JSON.parse(prop.value).v;
if ('qPixmapIconEngine' in icon)
{
var tableIcon = '<table border="1">';
tableIcon += '<tr>';
tableIcon += '<td>Image</td>';
tableIcon += '<td>Filename</td>';
tableIcon += '<td>Mode</td>';
tableIcon += '<td>State</td>';
tableIcon += '</tr>';
for (n = 0; n < icon.qPixmapIconEngine.length; n++)
{
var pixmap = icon.qPixmapIconEngine[n];
var img = '<img style="position:relative; left:'+0+'; top:'+0+'; width:'+pixmap.size.width+'; height:'+pixmap.size.height+';" src="data:image/png;base64,' + pixmap.pixmap + '"></img>';
tableIcon += '<tr>';
tableIcon += '<td>' + img + '</td>';
tableIcon += '<td>' + pixmap.filename + '</td>';
tableIcon += '<td>' + pixmap.mode + '</td>';
tableIcon += '<td>' + pixmap.state + '</td>';
tableIcon += '</tr>';
}
tableIcon += '</table>';
propertyValue = tableIcon;
}
}
if (prop.hasNotifySignal)
{
var id = objectName + '/' + prop.signal;
table += '<td id="' + id + '/prop">' + prop.value.substr(0, 100) + '</td>';
table += '<td id="' + id + '/prop">' + propertyValue + '</td>';
table += '<td>' + prop.signal + '</td>';
}
else
{
table += '<td>' + prop.value.substr(0, 100) + '</td>';
table += '<td>' + propertyValue + '</td>';
table += '<td>-</td>';
}

Expand Down
36 changes: 18 additions & 18 deletions inc/finalmq/Qt/qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class QtTypeHelper
// m_typesToField.emplace("QDateTime", MetaField{ MetaTypeId::TYPE_STRUCT, "", "", "", 0, {} });
m_typesToField.emplace("QUrl", MetaField{MetaTypeId::TYPE_BYTES, "", "", "", 0, {"qttype:QUrl,qtcode:bytes"}});
m_typesToField.emplace("QLocale", MetaField{MetaTypeId::TYPE_STRING, "", "", "", 0, {}});
m_typesToField.emplace("QPixmap", MetaField{MetaTypeId::TYPE_BYTES, "", "", "", 0, {"png:true"}});
m_typesToField.emplace("QPixmap", MetaField{ MetaTypeId::TYPE_BYTES, "", "", "", 0, {"png:true"} });

static const std::string KEY_QTTYPE = "qttype";

Expand Down Expand Up @@ -865,44 +865,44 @@ class ConnectObject : public QObject
}

private:
virtual int qt_metacall(QMetaObject::Call /*call*/, int /*methodId*/, void** params) override
virtual int qt_metacall(QMetaObject::Call /*call*/, int methodId, void** params) override
{
auto remoteEntity = m_remoteEntity.lock();
if(remoteEntity)
{
QVariantList args;
if(params[0] != nullptr)
if (methodId == m_metaMethod.methodIndex())
{
QVariantList args;
const QList<QByteArray> parameterTypes = m_metaMethod.parameterTypes();
for(int i = 0; i < parameterTypes.size(); ++i)
for (int i = 0; i < parameterTypes.size(); ++i)
{
const QByteArray& typeName = parameterTypes[i];
int type = QMetaType::type(typeName);
QVariant value(type, params[i + 1]);
const bool ok = isQVariantSerializable(value.type());
if(!ok)
if (!ok)
{
value = QString("!!! not serializable type: ") + QString::number(value.type());
}
args.append(std::move(value));
}
}

QByteArray bufferQt;
QDataStream streamParam(&bufferQt, QIODevice::WriteOnly);
streamParam << args;
QByteArray bufferQt;
QDataStream streamParam(&bufferQt, QIODevice::WriteOnly);
streamParam << args;

ZeroCopyBuffer bufferProto;
SerializerProto serializerProto(bufferProto);
ParserQt parserQt(serializerProto, bufferQt.data(), bufferQt.size(), ParserQt::Mode::WRAPPED_BY_QVARIANTLIST);
parserQt.parseStruct(m_typeName);
ZeroCopyBuffer bufferProto;
SerializerProto serializerProto(bufferProto);
ParserQt parserQt(serializerProto, bufferQt.data(), bufferQt.size(), ParserQt::Mode::WRAPPED_BY_QVARIANTLIST);
parserQt.parseStruct(m_typeName);

GeneralMessage message;
GeneralMessage message;

message.type = m_typeName;
bufferProto.copyData(message.data);
message.type = m_typeName;
bufferProto.copyData(message.data);

remoteEntity->sendEvent(m_peerId, m_path, message);
remoteEntity->sendEvent(m_peerId, m_path, message);
}
}
else
{
Expand Down
28 changes: 27 additions & 1 deletion inc/finalmq/Qt/qtdata.fmq
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@
{"name":"UTC", "id":1, "desc":""},
{"name":"OffsetFromUTC","id":2, "desc":""},
{"name":"TimeZone", "id":3, "desc":""}
]},
{"type":"FmqQIconMode","attrs":[],"desc":"","entries":[
{"name":"Normal", "id":0, "desc":""},
{"name":"Disabled", "id":1, "desc":""},
{"name":"Active", "id":2, "desc":""},
{"name":"Selected", "id":3, "desc":""}
]},
{"type":"FmqQIconState","attrs":[],"desc":"","entries":[
{"name":"On", "id":0, "desc":""},
{"name":"Off", "id":1, "desc":""}
]}

],
Expand Down Expand Up @@ -260,7 +270,7 @@
{"tid":"TYPE_UINT32", "type":"", "name":"typeId","attrs":["indexoffset:1,indexmode:mapping,0:0,1:1,2:2,3:3,4:4,5:5,6:6,32:7,33:8,34:9,35:10,36:11,37:12,38:13,31:14,7:15,10:16,11:17,12:18,13:19,14:20,15:21,16:22,17:23,18:24,19:25,20:26,21:27,22:28,23:29,24:30,25:31,26:32"],"desc":"desc","flags":["METAFLAG_INDEX"]},
{"tid":"TYPE_UINT8", "type":"", "name":"isnull","desc":"desc","flags":[]},

{"tid":"TYPE_UINT8", "name":"valueUnknown","desc":"desc","attrs":["fixedarray:0"],"flags":[]},
{"tid":"TYPE_ARRAY_INT8", "name":"valueUnknown","desc":"desc","attrs":["fixedarray:0"],"flags":[]},
{"tid":"TYPE_BOOL", "name":"valueBool"},
{"tid":"TYPE_INT32", "name":"valueInt"},
{"tid":"TYPE_UINT32", "name":"valueUInt"},
Expand Down Expand Up @@ -293,7 +303,23 @@
{"tid":"TYPE_STRUCT", "type":"FmqQLineF", "name":"valueQLineF"},
{"tid":"TYPE_STRUCT", "type":"FmqQPoint", "name":"valueQPoint"},
{"tid":"TYPE_STRUCT", "type":"FmqQPointF", "name":"valueQPointF"}
]},

{"type":"FmqQPixmapIconEngine","attrs":["qttype:QPixmapIconEngine"],"desc":"","fields":[
{"tid":"bytes", "name":"pixmap", "attrs":["png:true"], "desc":"", "flags":[]},
{"tid":"string", "name":"filename", "desc":"", "flags":[]},
{"tid":"struct", "type":"FmqQSize", "name":"size", "desc":"", "flags":[]},
{"tid":"enum", "type":"FmqQIconMode", "name":"mode", "desc":"", "flags":[]},
{"tid":"enum", "type":"FmqQIconState", "name":"state", "desc":"", "flags":[]}
]},

{"type":"FmqQIcon","attrs":["qttype:QIcon"],"desc":"","fields":[
{"tid":"string", "name":"iconEngineKey", "attrs":["indexmode:mapping,:0,QPixmapIconEngine:1"], "desc":"","flags":["METAFLAG_INDEX"]},
{"tid":"int8[]", "name":"valueNone", "desc":"desc","attrs":["fixedarray:0"],"flags":[]},
{"tid":"struct[]", "type":"FmqQPixmapIconEngine", "name":"qPixmapIconEngine", "desc":"","flags":[]}
]}



]
}
Expand Down
1 change: 1 addition & 0 deletions inc/finalmq/serialize/ParserAbortAndIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class SYMBOLEXP ParserAbortAndIndex : public IParserVisitor
virtual void enterArrayEnum(const MetaField& field, const std::vector<std::string>& value) override;

void checkIndex(const MetaField& field, std::int64_t value);
void checkIndex(const MetaField& field, const std::string& value);

IParserVisitor* m_visitor;

Expand Down
1 change: 1 addition & 0 deletions inc/finalmq/serializeqt/ParserQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace finalmq {

bool parseQVariantHeader(const MetaField& field);
void checkIndex(const MetaField& field, std::int64_t value, std::int64_t& index, std::int64_t& indexOffset);
void checkIndex(const MetaField& field, const std::string& value, std::int64_t& index, std::int64_t& indexOffset);
bool getPngSize(std::uint32_t& size);

bool parseSize(const MetaField& field, std::uint32_t& value);
Expand Down
76 changes: 68 additions & 8 deletions src/serialize/ParserAbortAndIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,7 @@ void ParserAbortAndIndex::enterDouble(const MetaField& field, double value)
}
void ParserAbortAndIndex::enterString(const MetaField& field, std::string&& value)
{
assert(!m_levelState.empty());
LevelState& levelState = m_levelState.back();
if ((levelState.abortStruct) || (levelState.index != INDEX_NOT_AVAILABLE && levelState.index != field.index && levelState.indexOfIndexField < field.index ))
{
return;
}

m_visitor->enterString(field, std::move(value));
enterString(field, value.c_str(), value.size());
}
void ParserAbortAndIndex::enterString(const MetaField& field, const char* value, ssize_t size)
{
Expand All @@ -319,6 +312,27 @@ void ParserAbortAndIndex::enterString(const MetaField& field, const char* value,
}

m_visitor->enterString(field, value, size);

// check abort
std::string strValue;
if (value)
{
strValue = std::string(value, &value[size]);
}
const std::string& valueAbort = field.getProperty(ABORTSTRUCT);
if (!valueAbort.empty())
{
std::vector<std::string> valuesAbort;
Utils::split(valueAbort, 0, valueAbort.size(), '|', valuesAbort);
if (std::find(valuesAbort.begin(), valuesAbort.end(), strValue) != valuesAbort.end())
{
levelState.abortStruct = ABORT_FIELD;
}
}
else
{
checkIndex(field, strValue);
}
}
void ParserAbortAndIndex::enterBytes(const MetaField& field, Bytes&& value)
{
Expand Down Expand Up @@ -793,4 +807,50 @@ void ParserAbortAndIndex::checkIndex(const MetaField& field, std::int64_t value)
}
}

void ParserAbortAndIndex::checkIndex(const MetaField& field, const std::string& value)
{
if ((field.flags & MetaFieldFlags::METAFLAG_INDEX) != 0)
{
assert(!m_levelState.empty());
LevelState& levelState = m_levelState.back();

std::int64_t indexOffset = 0;
const std::string& strIndexOffset = field.getProperty(INDEXOFFSET);
if (!strIndexOffset.empty())
{
indexOffset = atoll(strIndexOffset.c_str());
}
const std::string& indexmode = field.getProperty(INDEXMODE);
if (indexmode == INDEXMODE_MAPPING)
{
const std::string& strIndexMapped = field.getProperty(value);
if (strIndexMapped.empty())
{
levelState.abortStruct = ABORT_FIELD;
}
else
{
int indexMapped = atoi(strIndexMapped.c_str());
levelState.indexOfIndexField = field.index + indexOffset;
levelState.index = field.index + indexOffset + 1 + indexMapped;
}
}
else
{
const std::int64_t indexValue = atoll(value.c_str());
if (indexValue < 0)
{
levelState.abortStruct = ABORT_FIELD;
}
else
{
levelState.indexOfIndexField = field.index + indexOffset;
levelState.index = field.index + indexOffset + 1 + indexValue;
}
}
}
}



} // namespace finalmq
63 changes: 59 additions & 4 deletions src/serializeqt/ParserQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,13 @@ bool ParserQt::parseStructIntern(const MetaStruct& stru, bool wrappedByQVariant)
}
if (ok)
{
const char* buffer = nullptr;
ssize_t size = 0;
std::string value;

const std::string& code = field->getProperty(QT_CODE);
if (code == QT_CODE_BYTES)
{
const char* buffer = nullptr;
ssize_t size = 0;
ok = parseArrayByte(*field, buffer, size);
if (ok)
{
Expand All @@ -336,13 +338,28 @@ bool ParserQt::parseStructIntern(const MetaStruct& stru, bool wrappedByQVariant)
}
else
{
std::string value;
ok = parse(value, field);
if (ok)
{
m_visitor.enterString(*field, std::move(value));
m_visitor.enterString(*field, value.c_str(), value.size());
}
}

if (buffer)
{
value = std::string(buffer, &buffer[size]);
}
const std::string& valueAbort = field->getProperty(ABORTSTRUCT);
if (!valueAbort.empty())
{
std::vector<std::string> valuesAbort;
Utils::split(valueAbort, 0, valueAbort.size(), '|', valuesAbort);
abortStruct = (std::find(valuesAbort.begin(), valuesAbort.end(), value) != valuesAbort.end());
}
else
{
checkIndex(*field, value, index, indexOffset);
}
}
break;
case MetaTypeId::TYPE_BYTES:
Expand Down Expand Up @@ -1270,6 +1287,44 @@ void ParserQt::checkIndex(const MetaField& field, std::int64_t value, std::int64
}
}

void ParserQt::checkIndex(const MetaField& field, const std::string& value, std::int64_t& index, std::int64_t& indexOffset)
{
if ((field.flags & MetaFieldFlags::METAFLAG_INDEX) != 0)
{
const std::string& strIndexOffset = field.getProperty(INDEXOFFSET);
if (!strIndexOffset.empty())
{
indexOffset = atoll(strIndexOffset.c_str());
}
const std::string& indexmode = field.getProperty(INDEXMODE);
if (indexmode == INDEXMODE_MAPPING)
{
const std::string& strIndexMapped = field.getProperty(value);
if (strIndexMapped.empty())
{
index = INDEX_ABORTSTRUCT;
}
else
{
int indexMapped = atoi(strIndexMapped.c_str());
index = field.index + indexOffset + 1 + indexMapped;
}
}
else
{
const std::int64_t indexValue = atoll(value.c_str());
if (indexValue < 0)
{
index = INDEX_ABORTSTRUCT;
}
else
{
index = field.index + indexOffset + 1 + indexValue;
}
}
}
}

bool ParserQt::getPngSize(std::uint32_t& size)
{
static const std::uint8_t PNG_PREFIX[] = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
Expand Down
3 changes: 0 additions & 3 deletions src/serializeqt/SerializerQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ void SerializerQt::Internal::exitArrayStruct(const MetaField& /*field*/)
m_levelState.pop_back();
}

static const std::string ABORTSTRUCT = "abortstruct";
static const std::string ABORT_FALSE = "false";
static const std::string ABORT_TRUE = "true";

void SerializerQt::Internal::enterBool(const MetaField& field, bool value)
{
Expand Down
Loading

0 comments on commit 4538064

Please sign in to comment.