mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 16:55:36 +08:00
Issue #77 Use Qt facilites instead of own implementations
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/imageutils.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QIODevice>
|
||||
@@ -41,20 +40,20 @@ QString BlackMisc::pixmapToPngHexString(const QPixmap &pixmap)
|
||||
QByteArray ba;
|
||||
bool s = pixmapToPngByteArray(pixmap, ba);
|
||||
if (!s) { return QString(); }
|
||||
return bytesToHexString(ba);
|
||||
return ba.toHex();
|
||||
}
|
||||
|
||||
QPixmap BlackMisc::pngHexStringToPixmap(const QString &hexString)
|
||||
{
|
||||
if (hexString.isEmpty()) { return QPixmap(); }
|
||||
QByteArray ba(byteArrayFromHexString(hexString));
|
||||
QByteArray ba(QByteArray::fromHex(hexString.toLatin1()));
|
||||
return pngByteArrayToPixmap(ba);
|
||||
}
|
||||
|
||||
bool BlackMisc::pngHexStringToPixmapRef(const QString &hexString, QPixmap &pixmap)
|
||||
{
|
||||
if (hexString.isEmpty()) { return false; }
|
||||
QByteArray ba(byteArrayFromHexString(hexString));
|
||||
QByteArray ba(QByteArray::fromHex(hexString.toLatin1()));
|
||||
return pngByteArrayToPixmapRef(ba, pixmap);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "blackmisc/json.h"
|
||||
#include "blackmisc/imageutils.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QJsonDocument>
|
||||
@@ -95,7 +94,7 @@ const QJsonValue &operator >>(const QJsonValue &json, QPixmap &value)
|
||||
const QJsonValue &operator >>(const QJsonValue &json, QByteArray &value)
|
||||
{
|
||||
const QString hex(json.toString());
|
||||
value = BlackMisc::byteArrayFromHexString(hex);
|
||||
value = QByteArray::fromHex(hex.toLatin1());
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -175,7 +174,7 @@ QJsonValueRef operator >>(QJsonValueRef json, QPixmap &value)
|
||||
QJsonValueRef operator >>(QJsonValueRef json, QByteArray &value)
|
||||
{
|
||||
const QString hex(json.toString());
|
||||
value = BlackMisc::byteArrayFromHexString(hex);
|
||||
value = QByteArray::fromHex(hex.toLatin1());
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -248,7 +247,7 @@ QJsonArray &operator<<(QJsonArray &json, const QPixmap &value)
|
||||
|
||||
QJsonArray &operator<<(QJsonArray &json, const QByteArray &value)
|
||||
{
|
||||
QString pm(BlackMisc::byteArrayFromHexString(value));
|
||||
QString pm(QByteArray::fromHex(value));
|
||||
json.append(QJsonValue(pm));
|
||||
return json;
|
||||
}
|
||||
@@ -328,7 +327,7 @@ QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QPixma
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QByteArray &> &value)
|
||||
{
|
||||
QString pm(BlackMisc::bytesToHexString(value.second));
|
||||
QString pm(value.second.toHex());
|
||||
json.insert(value.first, pm);
|
||||
return json;
|
||||
}
|
||||
@@ -408,8 +407,7 @@ QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const QByteArray &> &value)
|
||||
{
|
||||
QString pm(BlackMisc::bytesToHexString(value.second));
|
||||
json[value.first] = pm;
|
||||
json[value.first] = QString(value.second.toHex());
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,34 +147,6 @@ namespace BlackMisc
|
||||
return QString(d, '0') + hex;
|
||||
}
|
||||
|
||||
QString bytesToHexString(const QByteArray &bytes)
|
||||
{
|
||||
QString h;
|
||||
for (int i = 0; i < bytes.size(); i++)
|
||||
{
|
||||
const int b = static_cast<int>(bytes.at(i));
|
||||
h += intToHex(b, 2);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
QByteArray byteArrayFromHexString(const QString &hexString)
|
||||
{
|
||||
QByteArray ba;
|
||||
int pos = 0;
|
||||
while (pos + 1 < hexString.length())
|
||||
{
|
||||
bool ok;
|
||||
const QString h = hexString.mid(pos, 2);
|
||||
int hex = h.toInt(&ok, 16);
|
||||
Q_ASSERT_X(ok, Q_FUNC_INFO, "Invalid hex");
|
||||
if (!ok) { return QByteArray(); }
|
||||
ba.push_back(static_cast<char>(hex));
|
||||
pos += 2;
|
||||
}
|
||||
return ba;
|
||||
}
|
||||
|
||||
QString stripDesignatorFromCompleterString(const QString &candidate)
|
||||
{
|
||||
const QString s(candidate.trimmed().toUpper());
|
||||
|
||||
@@ -247,12 +247,6 @@ namespace BlackMisc
|
||||
//! Replace dot '.' by locale decimal point
|
||||
BLACKMISC_EXPORT QString dotToLocaleDecimalPoint(const QString &input);
|
||||
|
||||
//! Int to hex value (per byte, 2 digits)
|
||||
BLACKMISC_EXPORT QString bytesToHexString(const QByteArray &bytes);
|
||||
|
||||
//! Byte array from hex value string per byte, 2 digits
|
||||
BLACKMISC_EXPORT QByteArray byteArrayFromHexString(const QString &hexString);
|
||||
|
||||
//! Strip a designator from a combined string
|
||||
BLACKMISC_EXPORT QString stripDesignatorFromCompleterString(const QString &candidate);
|
||||
|
||||
|
||||
@@ -53,12 +53,7 @@ namespace BlackMisc
|
||||
if (!object) { return false; }
|
||||
if (CThreadUtils::isCurrentThreadObjectThread(object)) { return false; }
|
||||
|
||||
QPointer<QObject> myself(object);
|
||||
QTimer::singleShot(0, object, [ = ]
|
||||
{
|
||||
if (!myself) { return; }
|
||||
callFunct();
|
||||
});
|
||||
QMetaObject::invokeMethod(object, callFunct);
|
||||
return true;
|
||||
}
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user