Mercurial > hg > syntilista
diff src/main.cpp @ 246:43a5e09bb832
Split some utility functions to util.{h,cpp}
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 08 May 2018 13:14:29 +0300 |
parents | 3d3ba5759cac |
children | 4f947840c806 |
line wrap: on
line diff
--- a/src/main.cpp Tue May 08 00:44:17 2018 +0300 +++ b/src/main.cpp Tue May 08 13:14:29 2018 +0300 @@ -14,7 +14,7 @@ #include "ui_mainwindow.h" #include "ui_aboutwindow.h" #include "runguard.h" - +#include "util.h" // @@ -56,103 +56,6 @@ // -// Convert QString to a double value, replacing comma -// -double slMoneyStrToValue(const QString &str) -{ - QString str2 = str; - return str2.replace(",", ".").toDouble(); -} - - -// -// Convert double value to formatted QString -// -QString slMoneyValueToStr(double val) -{ - return QStringLiteral("%1").arg(val, 1, 'f', 2); -} - - -QString slMoneyValueToStrSign(double val) -{ - return QStringLiteral("%1%2"). - arg(val > 0 ? "+" : ""). - arg(val, 1, 'f', 2); -} - - -// -// Trim and cleanup given QString (removing double whitespace etc.) -// -QString slCleanupStr(const QString &str) -{ - return str.simplified().trimmed(); -} - - -// -// Manipulate given QDateTime value to get desired -// correct timestamp. -// -const QDateTime slDateTimeToLocal(const QDateTime &val) -{ - QDateTime tmp = val; - tmp.setOffsetFromUtc(0); - return tmp.toLocalTime(); -} - - -// -// Return a string representation of given QDateTime -// converted to local time. -// -const QString slDateTimeToStr(const QDateTime &val) -{ - return slDateTimeToLocal(val).toString(QStringLiteral("yyyy-MM-dd hh:mm")); -} - - -// -// Error logging -// -void slLog(const QString &mtype, const QString &msg) -{ - QString filename = settings.dataPath + QDir::separator() + APP_LOG_FILE; - QFile fh(filename); - if (fh.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) - { - QTextStream out(&fh); - out << - slDateTimeToLocal(QDateTime::currentDateTimeUtc()). - toString(QStringLiteral("yyyy-MM-dd hh:mm:ss")) - << " [" << mtype << "]: " << msg << "\n"; - fh.close(); - } -} - - -// -// Display an error dialog with given title and message -// -int slErrorMsg(const QString &title, const QString &msg) -{ - QMessageBox dlg; - - slLog("ERROR", msg); - - dlg.setText(title); - dlg.setInformativeText(msg); - dlg.setTextFormat(Qt::RichText); - dlg.setIcon(QMessageBox::Critical); - dlg.setStandardButtons(QMessageBox::Ok); - dlg.setDefaultButton(QMessageBox::Ok); - - return dlg.exec(); -} - - -// // Check if an SQL error has occured (for given QSqlError) and // report it to stdout if so. Return "false" if error has occured, // true otherwise.