mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #303 Simulator table view
* Simulator component * Name / variant pair object / view / model
This commit is contained in:
@@ -16,21 +16,60 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CNameVariantPairModel::CNameVariantPairModel(QObject *parent) : CListModelBase("ViewNameVariantPairList", parent)
|
||||
CNameVariantPairModel::CNameVariantPairModel(bool withIcon, QObject *parent) : CListModelBase("ViewNameVariantPairList", parent)
|
||||
{
|
||||
this->setIconMode(withIcon);
|
||||
|
||||
// force strings for translation in resource files
|
||||
(void)QT_TRANSLATE_NOOP("ViewNameVariantPairList", "name");
|
||||
(void)QT_TRANSLATE_NOOP("ViewNameVariantPairList", "value");
|
||||
}
|
||||
|
||||
void CNameVariantPairModel::setIconMode(bool withIcon)
|
||||
{
|
||||
this->m_columns.clear();
|
||||
if (withIcon)
|
||||
{
|
||||
this->m_columns.addColumn(CColumn(CNameVariantPair::IndexPixmap, true));
|
||||
}
|
||||
this->m_columns.addColumn(CColumn("name", CNameVariantPair::IndexName));
|
||||
this->m_columns.addColumn(CColumn("value", CNameVariantPair::IndexVariant));
|
||||
|
||||
// default sort order
|
||||
this->setSortColumnByPropertyIndex(CNameVariantPair::IndexName);
|
||||
this->m_sortOrder = Qt::AscendingOrder;
|
||||
}
|
||||
|
||||
// force strings for translation in resource files
|
||||
(void)QT_TRANSLATE_NOOP("ViewNameVariantPairList", "name");
|
||||
(void)QT_TRANSLATE_NOOP("ViewNameVariantPairList", "value");
|
||||
void CNameVariantPairModel::addOrUpdateByName(const QString &name, const QString &value, const CIcon &icon)
|
||||
{
|
||||
int index = this->getNameRowIndex(name);
|
||||
QVariant qv(value);
|
||||
CNameVariantPair pair(name, qv, icon);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
// not in the list yet, append
|
||||
this->push_back(pair);
|
||||
}
|
||||
else
|
||||
{
|
||||
// already in list, update
|
||||
this->update(index, pair);
|
||||
}
|
||||
}
|
||||
|
||||
int CNameVariantPairModel::getNameRowIndex(const QString &name)
|
||||
{
|
||||
int rowIndex = this->m_container.getNameRowIndex(name);
|
||||
return rowIndex;
|
||||
}
|
||||
|
||||
void CNameVariantPairModel::removeByName(const QString &name)
|
||||
{
|
||||
int rowIndex = this->getNameRowIndex(name);
|
||||
if (rowIndex < 0) return;
|
||||
QModelIndex i = this->index(rowIndex, 0);
|
||||
this->remove(this->at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user