mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +08:00
Fixed property index class, class failedto work with DBus
This commit is contained in:
@@ -111,11 +111,18 @@ namespace BlackMisc
|
||||
//! Checked version from QVariant
|
||||
template <class T> void setFromQVariant(T *value, const QVariant &variant)
|
||||
{
|
||||
Q_ASSERT(variant.canConvert<T>());
|
||||
if (variant.canConvert<T>())
|
||||
{
|
||||
(*value) = variant.value<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString m = QString("Target type: %1 Variant type: %2 %3 %4").
|
||||
arg(qMetaTypeId<T>()).
|
||||
arg(static_cast<int>(variant.type())).arg(variant.userType()).arg(variant.typeName());
|
||||
Q_ASSERT_X(false, "setFromQVariant", m.toLocal8Bit().constData());
|
||||
Q_UNUSED(m);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -13,88 +13,82 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*
|
||||
* Non nested index
|
||||
*/
|
||||
CPropertyIndex::CPropertyIndex(int singleProperty)
|
||||
{
|
||||
Q_ASSERT(singleProperty >= static_cast<int>(GlobalIndexCValueObject));
|
||||
this->m_indexes.append(singleProperty);
|
||||
this->listToString();
|
||||
this->setIndexStringByList({singleProperty});
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct from initializer list
|
||||
*/
|
||||
CPropertyIndex::CPropertyIndex(std::initializer_list<int> il) :
|
||||
m_indexes(il)
|
||||
CPropertyIndex::CPropertyIndex(std::initializer_list<int> il)
|
||||
{
|
||||
this->listToString();
|
||||
this->setIndexStringByList(il);
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct from QList
|
||||
*/
|
||||
CPropertyIndex::CPropertyIndex(const QList<int> &indexes) :
|
||||
m_indexes(indexes)
|
||||
CPropertyIndex::CPropertyIndex(const QList<int> &indexes)
|
||||
{
|
||||
this->listToString();
|
||||
this->setIndexStringByList(indexes);
|
||||
}
|
||||
|
||||
/*
|
||||
* From string
|
||||
*/
|
||||
CPropertyIndex::CPropertyIndex(const QString &indexes) : m_indexString(indexes)
|
||||
{
|
||||
this->parseFromString(indexes);
|
||||
}
|
||||
|
||||
/*
|
||||
* Current property index, front element removed
|
||||
*/
|
||||
CPropertyIndex CPropertyIndex::copyFrontRemoved() const
|
||||
{
|
||||
Q_ASSERT(!this->m_indexes.isEmpty());
|
||||
if (this->m_indexes.isEmpty()) return CPropertyIndex();
|
||||
QList<int> c = this->m_indexes;
|
||||
c.removeAt(0);
|
||||
CPropertyIndex pi(c);
|
||||
Q_ASSERT(!this->isEmpty());
|
||||
if (this->isEmpty()) { return CPropertyIndex(); }
|
||||
QList<int> l = this->indexList();
|
||||
l.removeAt(0);
|
||||
CPropertyIndex pi(l);
|
||||
return pi;
|
||||
}
|
||||
|
||||
/*
|
||||
* Nested index
|
||||
*/
|
||||
bool CPropertyIndex::isNested() const
|
||||
{
|
||||
return this->m_indexes.size() > 1;
|
||||
return this->m_indexString.contains(';');
|
||||
}
|
||||
|
||||
bool CPropertyIndex::isMyself() const
|
||||
{
|
||||
return this->m_indexString.isEmpty();
|
||||
}
|
||||
|
||||
bool CPropertyIndex::isEmpty() const
|
||||
{
|
||||
return this->m_indexString.isEmpty();
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
QString CPropertyIndex::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
return this->m_indexString;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse from string
|
||||
*/
|
||||
void CPropertyIndex::parseFromString(const QString &indexes)
|
||||
{
|
||||
this->m_indexString = indexes.simplified().replace(" ", ";").replace(",", ";");
|
||||
this->stringToList();
|
||||
if (indexes.isEmpty())
|
||||
{
|
||||
this->m_indexString.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
QString is(indexes.simplified().replace(" ", ";").replace(",", ";"));
|
||||
if (is.endsWith(';'))
|
||||
{
|
||||
this->m_indexString = is.left(is.length() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_indexString = is;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* To string
|
||||
*/
|
||||
void CPropertyIndex::listToString()
|
||||
void CPropertyIndex::setIndexStringByList(const QList<int> &list)
|
||||
{
|
||||
QString l;
|
||||
foreach(int i, this->m_indexes)
|
||||
for (const int &i : list)
|
||||
{
|
||||
Q_ASSERT(i >= static_cast<int>(GlobalIndexCValueObject));
|
||||
if (!l.isEmpty()) { l.append(";"); }
|
||||
@@ -103,23 +97,21 @@ namespace BlackMisc
|
||||
this->m_indexString = l;
|
||||
}
|
||||
|
||||
/*
|
||||
* To int list
|
||||
*/
|
||||
void CPropertyIndex::stringToList()
|
||||
QList<int> CPropertyIndex::indexList() const
|
||||
{
|
||||
this->m_indexes.clear();
|
||||
if (this->m_indexString.isEmpty()) { return; }
|
||||
QList<int> list;
|
||||
if (this->m_indexString.isEmpty()) { return list; }
|
||||
QStringList indexes = this->m_indexString.split(';');
|
||||
foreach(QString index, indexes)
|
||||
{
|
||||
if (index.isEmpty()) continue;
|
||||
if (index.isEmpty()) { continue; }
|
||||
bool ok;
|
||||
int i = index.toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
Q_ASSERT(i >= static_cast<int>(GlobalIndexCValueObject));
|
||||
this->m_indexes.append(i);
|
||||
list.append(i);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -81,16 +81,20 @@ namespace BlackMisc
|
||||
bool isNested() const;
|
||||
|
||||
//! Myself index, used with nesting
|
||||
bool isMyself() const { return this->m_indexes.isEmpty(); }
|
||||
bool isMyself() const;
|
||||
|
||||
//! Empty?
|
||||
bool isEmpty() const { return this->m_indexes.isEmpty(); }
|
||||
bool isEmpty() const;
|
||||
|
||||
//! Index list
|
||||
QList<int> indexList() const;
|
||||
|
||||
//! First element casted to given type, usually then PropertIndex enum
|
||||
template<class CastType> CastType frontCasted() const
|
||||
{
|
||||
Q_ASSERT(!this->m_indexes.isEmpty());
|
||||
int f = this->m_indexes.isEmpty() ? 0 : this->m_indexes.first();
|
||||
QList<int> l = indexList();
|
||||
Q_ASSERT(!l.isEmpty());
|
||||
int f = l.isEmpty() ? 0 : l.first();
|
||||
return static_cast<CastType>(f);
|
||||
}
|
||||
|
||||
@@ -98,8 +102,9 @@ namespace BlackMisc
|
||||
template<class EnumType> bool equalsPropertyIndexEnum(EnumType ev)
|
||||
{
|
||||
static_assert(std::is_enum<EnumType>::value, "Argument must be an enum");
|
||||
if (this->m_indexes.size() != 1) { return false; }
|
||||
return static_cast<int>(ev) == m_indexes.first();
|
||||
QList<int> l = indexList();
|
||||
if (l.size() != 1) { return false; }
|
||||
return static_cast<int>(ev) == l.first();
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -111,14 +116,10 @@ namespace BlackMisc
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CPropertyIndex)
|
||||
QList<int> m_indexes;
|
||||
QString m_indexString; //! I use a little trick here, the string is used with the tupel system, as it provides all operators, hash ..
|
||||
|
||||
//! Convert list to string
|
||||
void listToString();
|
||||
|
||||
//! String to list
|
||||
void stringToList();
|
||||
void setIndexStringByList(const QList<int> &list);
|
||||
|
||||
};
|
||||
} //namespace
|
||||
|
||||
Reference in New Issue
Block a user