27 removeButton->setEnabled(
false );
33 mModel.setReadOnly( readOnly );
38void QgsKeyValueModel::setMap(
const QVariantMap &map )
42 for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
44 mLines.append( Line( it.key(), it.value() ) );
49QVariantMap QgsKeyValueModel::map()
const
52 for ( QVector<Line>::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
54 if ( !it->first.isEmpty() )
56 ret[it->first] = it->second;
62QgsKeyValueModel::QgsKeyValueModel( QObject *parent ) :
63 QAbstractTableModel( parent )
67int QgsKeyValueModel::rowCount(
const QModelIndex &parent )
const
70 return mLines.count();
73int QgsKeyValueModel::columnCount(
const QModelIndex &parent )
const
79QVariant QgsKeyValueModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
81 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
83 return QObject::tr( section == 0 ?
"Key" :
"Value" );
88QVariant QgsKeyValueModel::data(
const QModelIndex &index,
int role )
const
90 if ( index.row() < 0 ||
91 index.row() >= mLines.count() ||
92 ( role != Qt::DisplayRole && role != Qt::EditRole ) )
96 if ( index.column() == 0 )
97 return mLines.at( index.row() ).first;
98 if ( index.column() == 1 )
99 return mLines.at( index.row() ).second;
103bool QgsKeyValueModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
108 if ( index.row() < 0 || index.row() >= mLines.count() || role != Qt::EditRole )
112 if ( index.column() == 0 )
114 mLines[index.row()].first = value.toString();
118 mLines[index.row()].second = value;
120 emit dataChanged( index, index );
124Qt::ItemFlags QgsKeyValueModel::flags(
const QModelIndex &index )
const
127 return QAbstractTableModel::flags( index ) | Qt::ItemIsEditable;
129 return QAbstractTableModel::flags( index );
132bool QgsKeyValueModel::insertRows(
int position,
int rows,
const QModelIndex &parent )
138 beginInsertRows( QModelIndex(), position, position + rows - 1 );
139 for (
int i = 0; i < rows; ++i )
141 mLines.insert( position, Line( QString(), QVariant() ) );
147bool QgsKeyValueModel::removeRows(
int position,
int rows,
const QModelIndex &parent )
153 beginRemoveRows( QModelIndex(), position, position + rows - 1 );
154 mLines.remove( position, rows );
159void QgsKeyValueModel::setReadOnly(
bool readOnly )
161 mReadOnly = readOnly;