20 , mModel( subType, this )
28 removeButton->setEnabled(
false );
29 mModel.setList(
list );
34QgsListModel::QgsListModel( QVariant::Type subType, QObject *parent ) :
35 QAbstractTableModel( parent ),
40void QgsListModel::setList(
const QVariantList &list )
47QVariantList QgsListModel::list()
const
50 for ( QVariantList::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
53 if ( cur.convert( mSubType ) )
59bool QgsListModel::valid()
const
61 for ( QVariantList::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
64 if ( !cur.convert( mSubType ) )
return false;
69int QgsListModel::rowCount(
const QModelIndex &parent )
const
72 return mLines.count();
75int QgsListModel::columnCount(
const QModelIndex &parent )
const
81QVariant QgsListModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
83 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0 )
85 return QObject::tr(
"Value" );
90QVariant QgsListModel::data(
const QModelIndex &index,
int role )
const
92 if ( index.row() < 0 ||
93 index.row() >= mLines.count() ||
94 ( role != Qt::DisplayRole && role != Qt::EditRole ) ||
97 return QVariant( mSubType );
99 return mLines.at( index.row() );
102bool QgsListModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
104 if ( index.row() < 0 || index.row() >= mLines.count() ||
105 index.column() != 0 || role != Qt::EditRole )
109 mLines[index.row()] = value.toString();
110 emit dataChanged( index, index );
114Qt::ItemFlags QgsListModel::flags(
const QModelIndex &index )
const
116 return QAbstractTableModel::flags( index ) | Qt::ItemIsEditable;
119bool QgsListModel::insertRows(
int position,
int rows,
const QModelIndex &parent )
122 beginInsertRows( QModelIndex(), position, position + rows - 1 );
123 for (
int i = 0; i < rows; ++i )
125 mLines.insert( position, QVariant( mSubType ) );
131bool QgsListModel::removeRows(
int position,
int rows,
const QModelIndex &parent )
134 beginRemoveRows( QModelIndex(), position, position + rows - 1 );
135 for (
int i = 0; i < rows; ++i )
136 mLines.removeAt( position );