1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-25 20:22:39 +01:00

Add QVersionNumber parser from QString

This commit is contained in:
Elias Steurer 2019-09-01 12:01:08 +02:00
parent 31f00e37a9
commit de8afdc9cd
2 changed files with 26 additions and 3 deletions

View File

@ -94,6 +94,24 @@ QString Util::generateRandomString(quint32 length)
return randomString;
}
std::optional<QVersionNumber> Util::getVersionNumberFromString(const QString& str)
{
// Must be: Major.Minor.Patch
bool okMajor { false };
bool okMinor { false };
bool okPatch { false };
int major = QString(str.at(0)).toInt(&okMajor);
int minor = QString(str.at(2)).toInt(&okMinor);
int patch = QString(str.at(4)).toInt(&okPatch);
if (okMajor && okMinor && okPatch) {
return std::nullopt;
}
return QVersionNumber(major, minor, patch);
}
void Util::setNavigation(QString nav)
{
emit requestNavigation(nav);
@ -272,14 +290,14 @@ void Util::logToGui(QtMsgType type, const QMessageLogContext& context, const QSt
QByteArray line = "in line " + QByteArray::number(context.line) + ", ";
QByteArray function = "function " + QByteArray(context.function) + ", Message: ";
QString log = "&emsp; <font color=\"#03A9F4\"> "+ QDateTime::currentDateTime().toString() + "</font> &emsp; " + localMsg + "<br><br>";
QString log = "&emsp; <font color=\"#03A9F4\"> " + QDateTime::currentDateTime().toString() + "</font> &emsp; " + localMsg + "<br><br>";
switch (type) {
case QtDebugMsg:
log.prepend("<b><font color=\"##78909C\"> Debug</font>:</b>");
break;
case QtInfoMsg:
log.prepend("<b><font color=\"#8BC34A\"> Info</font>:</b>");
log.prepend("<b><font color=\"#8BC34A\"> Info</font>:</b>");
break;
case QtWarningMsg:
log.prepend("<b><font color=\"#FFC107\"> Warning</font>:</b>");
@ -288,7 +306,7 @@ void Util::logToGui(QtMsgType type, const QMessageLogContext& context, const QSt
log.prepend("<b><font color=\"#FF5722\"> Critical</font>:</b>");
break;
case QtFatalMsg:
log.prepend("<b><font color=\"#F44336\"> Fatal</font>:</b>");
log.prepend("<b><font color=\"#F44336\"> Fatal</font>:</b>");
break;
}
@ -314,4 +332,5 @@ bool Util::saveExtractedByteArray(libzippp::ZipEntry& entry, std::string& absolu
return true;
}
}

View File

@ -13,6 +13,7 @@
#include <QDateTime>
#include <QNetworkReply>
#include <QProcess>
#include <QVersionNumber>
#include <qqml.h>
#include <fstream>
@ -82,6 +83,9 @@ signals:
public slots:
static std::optional<QJsonObject> openJsonFileToObject(const QString& path);
static std::optional<QString> openJsonFileToString(const QString& path);
static std::optional<QVersionNumber> getVersionNumberFromString(const QString& str);
static QString generateRandomString(quint32 length = 32);
void setNavigation(QString nav);