27   removeButton->setEnabled( 
false );
 
   32 void QgsKeyValueModel::setMap( 
const QVariantMap &map )
 
   36   for ( QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it )
 
   38     mLines.append( Line( it.key(), it.value() ) );
 
   43 QVariantMap QgsKeyValueModel::map()
 const 
   46   for ( QVector<Line>::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
 
   48     if ( !it->first.isEmpty() )
 
   50       ret[it->first] = it->second;
 
   56 QgsKeyValueModel::QgsKeyValueModel( QObject *parent ) :
 
   57   QAbstractTableModel( parent )
 
   61 int QgsKeyValueModel::rowCount( 
const QModelIndex &parent )
 const 
   64   return mLines.count();
 
   67 int QgsKeyValueModel::columnCount( 
const QModelIndex &parent )
 const 
   73 QVariant QgsKeyValueModel::headerData( 
int section, Qt::Orientation orientation, 
int role )
 const 
   75   if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
 
   77     return QObject::tr( section == 0 ? 
"Key" : 
"Value" );
 
   82 QVariant QgsKeyValueModel::data( 
const QModelIndex &index, 
int role )
 const 
   84   if ( index.row() < 0 ||
 
   85        index.row() >= mLines.count() ||
 
   86        ( role != Qt::DisplayRole && role != Qt::EditRole ) )
 
   90   if ( index.column() == 0 )
 
   91     return mLines.at( index.row() ).first;
 
   92   if ( index.column() == 1 )
 
   93     return mLines.at( index.row() ).second;
 
   97 bool QgsKeyValueModel::setData( 
const QModelIndex &index, 
const QVariant &value, 
int role )
 
   99   if ( index.row() < 0 || index.row() >= mLines.count() || role != Qt::EditRole )
 
  103   if ( index.column() == 0 )
 
  105     mLines[index.row()].first = value.toString();
 
  109     mLines[index.row()].second = value;
 
  111   emit dataChanged( index, index );
 
  115 Qt::ItemFlags QgsKeyValueModel::flags( 
const QModelIndex &index )
 const 
  117   return QAbstractTableModel::flags( index ) | Qt::ItemIsEditable;
 
  120 bool QgsKeyValueModel::insertRows( 
int position, 
int rows, 
const QModelIndex &parent )
 
  123   beginInsertRows( QModelIndex(), position, position + rows - 1 );
 
  124   for ( 
int i = 0; i < rows; ++i )
 
  126     mLines.insert( position, Line( QString(), QVariant() ) );
 
  132 bool QgsKeyValueModel::removeRows( 
int position, 
int rows, 
const QModelIndex &parent )
 
  135   beginRemoveRows( QModelIndex(), position, position + rows - 1 );
 
  136   mLines.remove( position, rows );