mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-11-29 11:56:37 -05:00
Removed most of the usages of std::ostringstream in the gui.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5056 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9ef7d08d2b
commit
4cb844c44d
38 changed files with 190 additions and 354 deletions
|
|
@ -175,21 +175,21 @@ QString misc::userFriendlyDuration(qlonglong seconds)
|
|||
}
|
||||
int minutes = seconds / 60;
|
||||
if(minutes < 60) {
|
||||
return tr("%1 minutes","e.g: 10minutes").arg(QString::QString::fromUtf8(misc::toString(minutes).c_str()));
|
||||
return tr("%1 minutes","e.g: 10minutes").arg(minutes);
|
||||
}
|
||||
int hours = minutes / 60;
|
||||
minutes = minutes - hours*60;
|
||||
if(hours < 24) {
|
||||
return tr("%1h %2m", "e.g: 3hours 5minutes").arg(QString::fromUtf8(misc::toString(hours).c_str())).arg(QString::fromUtf8(misc::toString(minutes).c_str()));
|
||||
return tr("%1h %2m", "e.g: 3hours 5minutes").arg(hours).arg(minutes);
|
||||
}
|
||||
int days = hours / 24;
|
||||
hours = hours - days * 24;
|
||||
if(days < 365) {
|
||||
return tr("%1d %2h", "e.g: 2days 10hours").arg(QString::fromUtf8(misc::toString(days).c_str())).arg(QString::fromUtf8(misc::toString(hours).c_str()));
|
||||
return tr("%1d %2h", "e.g: 2days 10hours").arg(days).arg(hours);
|
||||
}
|
||||
int years = days / 365;
|
||||
days = days - years * 365;
|
||||
return tr("%1y %2d", "e.g: 2 years 2days ").arg(QString::fromUtf8(misc::toString(years).c_str())).arg(QString::fromUtf8(misc::toString(days).c_str()));
|
||||
return tr("%1y %2d", "e.g: 2 years 2days ").arg(years).arg(days);
|
||||
}
|
||||
|
||||
QString misc::userFriendlyUnit(double count, unsigned int decimal, double factor)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <QObject>
|
||||
#include <QPair>
|
||||
|
|
@ -39,45 +38,45 @@ class misc : public QObject
|
|||
public:
|
||||
// Convert any type of variable to C++ String
|
||||
// convert=true will convert -1 to 0
|
||||
template <class T> static std::string toString(const T& x, bool convert=false) {
|
||||
std::ostringstream o;
|
||||
if(!(o<<x)) {
|
||||
throw std::runtime_error("::toString()");
|
||||
}
|
||||
if(o.str() == "-1" && convert)
|
||||
return "0";
|
||||
return o.str();
|
||||
}
|
||||
// template <class T> static std::string toString(const T& x, bool convert=false) {
|
||||
// std::ostringstream o;
|
||||
// if(!(o<<x)) {
|
||||
// throw std::runtime_error("::toString()");
|
||||
// }
|
||||
// if(o.str() == "-1" && convert)
|
||||
// return "0";
|
||||
// return o.str();
|
||||
// }
|
||||
|
||||
template <class T> static QString toQString(const T& x, bool convert=false) {
|
||||
std::ostringstream o;
|
||||
if(!(o<<x)) {
|
||||
throw std::runtime_error("::toString()");
|
||||
}
|
||||
if(o.str() == "-1" && convert)
|
||||
return QString::fromUtf8("0");
|
||||
return QString::fromUtf8(o.str().c_str());
|
||||
}
|
||||
// template <class T> static QString toQString(const T& x, bool convert=false) {
|
||||
// std::ostringstream o;
|
||||
// if(!(o<<x)) {
|
||||
// throw std::runtime_error("::toString()");
|
||||
// }
|
||||
// if(o.str() == "-1" && convert)
|
||||
// return QString::fromUtf8("0");
|
||||
// return QString::fromUtf8(o.str().c_str());
|
||||
// }
|
||||
|
||||
template <class T> static QByteArray toQByteArray(const T& x, bool convert=false) {
|
||||
std::ostringstream o;
|
||||
if(!(o<<x)) {
|
||||
throw std::runtime_error("::toString()");
|
||||
}
|
||||
if(o.str() == "-1" && convert)
|
||||
return "0";
|
||||
return QByteArray(o.str().c_str());
|
||||
}
|
||||
// template <class T> static QByteArray toQByteArray(const T& x, bool convert=false) {
|
||||
// std::ostringstream o;
|
||||
// if(!(o<<x)) {
|
||||
// throw std::runtime_error("::toString()");
|
||||
// }
|
||||
// if(o.str() == "-1" && convert)
|
||||
// return "0";
|
||||
// return QByteArray(o.str().c_str());
|
||||
// }
|
||||
|
||||
// Convert C++ string to any type of variable
|
||||
template <class T> static T fromString(const std::string& s) {
|
||||
T x;
|
||||
std::istringstream i(s);
|
||||
if(!(i>>x)) {
|
||||
throw std::runtime_error("::fromString()");
|
||||
}
|
||||
return x;
|
||||
}
|
||||
// template <class T> static T fromString(const std::string& s) {
|
||||
// T x;
|
||||
// std::istringstream i(s);
|
||||
// if(!(i>>x)) {
|
||||
// throw std::runtime_error("::fromString()");
|
||||
// }
|
||||
// return x;
|
||||
// }
|
||||
|
||||
// template <class T> static T fromQString::fromUtf8(const QString& s) {
|
||||
// T x;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue