mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
refs #247 Removed code which is no longer used.
This commit is contained in:
@@ -137,151 +137,6 @@ void BlackMisc::initResources()
|
||||
initBlackMiscResources();
|
||||
}
|
||||
|
||||
/*
|
||||
* Stupid extension bo be able to compare 2 QVariants
|
||||
*/
|
||||
bool BlackMisc::equalQVariants(const QVariant &v1, const QVariant &v2)
|
||||
{
|
||||
// Compares this QVariant with v and returns true if they are equal; otherwise returns false.
|
||||
// In the case of custom types, their equalness operators are not called. Instead the values' addresses are compared.
|
||||
if (v1 == v2) return true;
|
||||
|
||||
// shortcuts
|
||||
if (!v1.isValid() || !v2.isValid()) return false;
|
||||
if (v1.type() != v2.type()) return false;
|
||||
if (v1.userType() != v2.userType()) return false;
|
||||
|
||||
// I have same types now
|
||||
int c = compareQVariants(v1, v2);
|
||||
return c == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare values
|
||||
*/
|
||||
int BlackMisc::compareQVariants(const QVariant &v1, const QVariant &v2)
|
||||
{
|
||||
// Compares this QVariant with v and returns true if they are equal; otherwise returns false.
|
||||
// In the case of custom types, their equalness operators are not called. Instead the values' addresses are compared.
|
||||
if (v1 == v2) return 0;
|
||||
|
||||
if (!v1.isValid() || !v2.isValid()) qFatal("Invalid variants");
|
||||
if (v1.type() != v2.type()) qFatal("Mismatching types");
|
||||
if (v1.userType() != v2.userType()) qFatal("Mismatching user types");
|
||||
|
||||
auto v1Type = static_cast<QMetaType::Type>(v1.type());
|
||||
switch (v1Type)
|
||||
{
|
||||
case QMetaType::QString:
|
||||
case QMetaType::QChar:
|
||||
{
|
||||
QString s1 = v1.value<QString>();
|
||||
QString s2 = v2.value<QString>();
|
||||
return s1.compare(s2);
|
||||
}
|
||||
case QMetaType::QDateTime:
|
||||
{
|
||||
QDateTime dt1 = v1.value<QDateTime>();
|
||||
QDateTime dt2 = v2.value<QDateTime>();
|
||||
if (dt1 == dt2) return 0;
|
||||
return dt1 < dt2 ? -1 : 1;
|
||||
}
|
||||
case QMetaType::QDate:
|
||||
{
|
||||
QDate d1 = v1.value<QDate>();
|
||||
QDate d2 = v2.value<QDate>();
|
||||
if (d1 == d2) return 0;
|
||||
return d1 < d2 ? -1 : 1;
|
||||
}
|
||||
case QMetaType::QTime:
|
||||
{
|
||||
QTime t1 = v1.value<QTime>();
|
||||
QTime t2 = v2.value<QTime>();
|
||||
if (t1 == t2) return 0;
|
||||
return t1 < t2 ? -1 : 1;
|
||||
}
|
||||
case QMetaType::QPixmap:
|
||||
{
|
||||
QPixmap p1 = v1.value<QPixmap>();
|
||||
QPixmap p2 = v2.value<QPixmap>();
|
||||
if (p1.width() == p2.width()) return 0;
|
||||
return p1.width() < p2.width() ? -1 : 1;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// CValueObject
|
||||
if (v1Type == QMetaType::User)
|
||||
{
|
||||
const CValueObject *cs1 = CValueObject::fromQVariant(v1);
|
||||
const CValueObject *cs2 = CValueObject::fromQVariant(v2);
|
||||
if (cs1 && cs2)
|
||||
{
|
||||
return compare(*cs1, *cs2);
|
||||
}
|
||||
}
|
||||
|
||||
// integer types, handling not as double for rounding issues
|
||||
if (v1Type == QMetaType::Int)
|
||||
{
|
||||
int i1 = v1.value<int>();
|
||||
int i2 = v2.value<int>();
|
||||
if (i1 == i2) return 0;
|
||||
return i1 < i2 ? -1 : 1;
|
||||
}
|
||||
else if (v1Type == QMetaType::UInt)
|
||||
{
|
||||
uint i1 = v1.value<uint>();
|
||||
uint i2 = v2.value<uint>();
|
||||
if (i1 == i2) return 0;
|
||||
return i1 < i2 ? -1 : 1;
|
||||
}
|
||||
else if (v1Type == QMetaType::LongLong)
|
||||
{
|
||||
long long i1 = v1.value<long long>();
|
||||
long long i2 = v2.value<long long>();
|
||||
if (i1 == i2) return 0;
|
||||
return i1 < i2 ? -1 : 1;
|
||||
}
|
||||
else if (v1Type == QMetaType::ULongLong)
|
||||
{
|
||||
unsigned long long i1 = v1.value<unsigned long long>();
|
||||
unsigned long long i2 = v2.value<unsigned long long>();
|
||||
if (i1 == i2) return 0;
|
||||
return i1 < i2 ? -1 : 1;
|
||||
}
|
||||
|
||||
// all kind of numeric values
|
||||
if (v1.canConvert<double>())
|
||||
{
|
||||
double d1 = v1.value<double>();
|
||||
double d2 = v2.value<double>();
|
||||
if (d1 == d2) return 0;
|
||||
return d1 < d2 ? -1 : 1;
|
||||
}
|
||||
|
||||
qFatal("Unknown type for compare");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* To string
|
||||
*/
|
||||
QString BlackMisc::qVariantToString(const QVariant &qv, bool i18n)
|
||||
{
|
||||
if (qv.type() != QVariant::UserType) return qv.toString();
|
||||
const CValueObject *s = CValueObject::fromQVariant(qv);
|
||||
if (s)
|
||||
{
|
||||
return s->toQString(i18n);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add hash values
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user