mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #325, name variant pair allows test for existing values
* equal value updates can be skipped * equalsQVariant in CValueObject * resizing parameter for views
This commit is contained in:
@@ -40,25 +40,27 @@ namespace BlackGui
|
||||
this->m_sortOrder = Qt::AscendingOrder;
|
||||
}
|
||||
|
||||
void CNameVariantPairModel::addOrUpdateByName(const QString &name, const QString &value, const CIcon &icon)
|
||||
bool CNameVariantPairModel::addOrUpdateByName(const QString &name, const QVariant &value, const CIcon &icon, bool skipEqualValues)
|
||||
{
|
||||
int index = this->getNameRowIndex(name);
|
||||
QVariant qv(value);
|
||||
CNameVariantPair pair(name, qv, icon);
|
||||
int index = this->getRowIndexForName(name);
|
||||
CNameVariantPair pair(name, value, icon);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
// not in the list yet, append
|
||||
this->push_back(pair);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// already in list, update
|
||||
if (skipEqualValues && this->containsNameValue(name, value)) { return false; }
|
||||
this->update(index, pair);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int CNameVariantPairModel::getNameRowIndex(const QString &name)
|
||||
int CNameVariantPairModel::getRowIndexForName(const QString &name) const
|
||||
{
|
||||
int rowIndex = this->m_container.getNameRowIndex(name);
|
||||
return rowIndex;
|
||||
@@ -66,10 +68,24 @@ namespace BlackGui
|
||||
|
||||
void CNameVariantPairModel::removeByName(const QString &name)
|
||||
{
|
||||
int rowIndex = this->getNameRowIndex(name);
|
||||
int rowIndex = this->getRowIndexForName(name);
|
||||
if (rowIndex < 0) return;
|
||||
QModelIndex i = this->index(rowIndex, 0);
|
||||
this->remove(this->at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CNameVariantPairModel::containsName(const QString &name) const
|
||||
{
|
||||
return this->m_container.containsName(name);
|
||||
}
|
||||
|
||||
bool CNameVariantPairModel::containsNameValue(const QString &name, const QVariant &value) const
|
||||
{
|
||||
int rowIndex = this->getRowIndexForName(name);
|
||||
if (rowIndex < 0) return false;
|
||||
QModelIndex i = this->index(rowIndex, 0);
|
||||
const CNameVariantPair cv = this->at(i);
|
||||
return BlackMisc::equalQVariants(value, cv.toQVariant());
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -33,20 +33,26 @@ namespace BlackGui
|
||||
//! Constructor
|
||||
explicit CNameVariantPairModel(bool withIcon, QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CNameVariantPairModel() {}
|
||||
|
||||
//! Icon on / off
|
||||
void setIconMode(bool withIcon);
|
||||
|
||||
//! Remove by given name
|
||||
void removeByName(const QString &name);
|
||||
|
||||
//! Contains name already?
|
||||
bool containsName(const QString &name) const;
|
||||
|
||||
//! Contains name / value?
|
||||
bool containsNameValue(const QString &name, const QVariant &value) const;
|
||||
|
||||
//! Add our update a value
|
||||
void addOrUpdateByName(const QString &name, const QString &value, const BlackMisc::CIcon &icon);
|
||||
bool addOrUpdateByName(const QString &name, const QVariant &value, const BlackMisc::CIcon &icon, bool skipEqualValues);
|
||||
|
||||
//! Current row index of given name
|
||||
int getNameRowIndex(const QString &name);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CNameVariantPairModel() {}
|
||||
int getRowIndexForName(const QString &name) const;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user