127 lines
3.3 KiB
C++
Executable File
127 lines
3.3 KiB
C++
Executable File
/**
|
|
*
|
|
* @RDE_HEADER@
|
|
* Helper model for SymbolModificationWidget
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "field_table_model.h"
|
|
|
|
namespace AdvancedSymbology
|
|
{
|
|
namespace Gui
|
|
{
|
|
|
|
int FieldTableModel::columnCount(const QModelIndex &parent) const
|
|
{
|
|
return parent.isValid() ? 0 : 2;
|
|
}
|
|
|
|
int FieldTableModel::rowCount(const QModelIndex &parent) const
|
|
{
|
|
return parent.isValid() ? 0 : m_fieldKeys.size();
|
|
}
|
|
|
|
QVariant FieldTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
{
|
|
if (role != Qt::DisplayRole) return QVariant();
|
|
if (Qt::Orientation::Horizontal == orientation)
|
|
{
|
|
switch (section)
|
|
{
|
|
case 0 : return tr("Field Title");
|
|
case 1 : return tr("Value");
|
|
default : break;
|
|
}
|
|
}
|
|
return QVariant();
|
|
} // QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
|
|
|
|
|
|
QVariant FieldTableModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (index.row() >= 0 && index.row() < m_fieldKeys.size() &&
|
|
role == Qt::DisplayRole)
|
|
{
|
|
const QString &key = m_fieldKeys.at(index.row());
|
|
switch (index.column())
|
|
{
|
|
case 0 : return key;
|
|
case 1 : return m_fieldValueMap[key];
|
|
default : QVariant();
|
|
}
|
|
}
|
|
return QVariant();
|
|
} // QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override
|
|
|
|
bool FieldTableModel::setFieldAttrMap(const QMap<QString, QVariant> &fieldAttrMap)
|
|
{
|
|
beginResetModel();
|
|
{
|
|
m_fieldKeys = fieldAttrMap.keys();
|
|
m_fieldKeys.sort();
|
|
m_fieldValueMap = fieldAttrMap;
|
|
}
|
|
endResetModel();
|
|
return true;
|
|
} // bool setFieldAttrMap( const QMap<QString,QVariant> & fieldAttrMap )
|
|
|
|
|
|
void FieldTableModel::setFieldAttribute(const QString &key, const QString &value)
|
|
{
|
|
beginResetModel();
|
|
{
|
|
m_fieldValueMap[key] = value;
|
|
if (!m_fieldKeys.contains(key))
|
|
{
|
|
m_fieldKeys += key;
|
|
m_fieldKeys.sort();
|
|
}
|
|
}
|
|
endResetModel();
|
|
} // void setFieldAttribute( const QString & key, const QString & value )
|
|
|
|
|
|
void FieldTableModel::setFieldAttribute(SituationMap::Participant::TextModifier textMod, const QString &value)
|
|
{
|
|
const QString &key = participantAttributeKey(textMod);
|
|
if (!key.isEmpty()) setFieldAttribute(key, value);
|
|
} // void setFieldAttribute(SituationMap::TextModifier textMod, const QString & value)
|
|
|
|
|
|
void FieldTableModel::removeFieldAttrMap(const QString &key)
|
|
{
|
|
if (m_fieldKeys.contains(key))
|
|
{
|
|
beginResetModel();
|
|
{
|
|
m_fieldKeys.removeAll(key);
|
|
m_fieldValueMap.remove(key);
|
|
}
|
|
endResetModel();
|
|
}
|
|
} // void removeFieldAttrMap( const QString & key )
|
|
|
|
|
|
QString FieldTableModel::fieldAttribute(const QString &key) const
|
|
{
|
|
return m_fieldValueMap.value(key).toString();
|
|
} // void fieldAttribute( const QString & key )
|
|
|
|
QString FieldTableModel::fieldAttribute(SituationMap::Participant::TextModifier textMod)
|
|
{
|
|
const QString &key = participantAttributeKey(textMod);
|
|
if (key.isEmpty()) return QString();
|
|
return fieldAttribute(key);
|
|
} // QString fieldAttribute( SituationMap::TextModifier textMod )
|
|
|
|
QString FieldTableModel::participantAttributeKey(SituationMap::Participant::TextModifier textMod)
|
|
{
|
|
return SituationMap::Participant::toString(textMod);
|
|
} // QString participantAttributeKey(SituationMap::TextModifier textMod)
|
|
|
|
} // namespace Gui
|
|
} // namespace AdvancedSymbology
|