20#include "moc_qgslistwidget.cpp"
24 , mModel( subType, this )
31 removeButton->setEnabled(
false );
32 mModel.setList(
list );
37 mModel.setReadOnly( readOnly );
43QgsListModel::QgsListModel( QMetaType::Type subType, QObject *parent )
44 : QAbstractTableModel( parent ), mSubType( subType )
48void QgsListModel::setList(
const QVariantList &list )
55QVariantList QgsListModel::list()
const
58 for ( QVariantList::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
61 if ( cur.convert( mSubType ) )
67bool QgsListModel::valid()
const
69 for ( QVariantList::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
72 if ( !cur.convert( mSubType ) )
78int QgsListModel::rowCount(
const QModelIndex &parent )
const
81 return mLines.count();
84int QgsListModel::columnCount(
const QModelIndex &parent )
const
90QVariant QgsListModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
92 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0 )
94 return QObject::tr(
"Value" );
99QVariant QgsListModel::data(
const QModelIndex &index,
int role )
const
101 if ( index.row() < 0 || index.row() >= mLines.count() || ( role != Qt::DisplayRole && role != Qt::EditRole ) || index.column() != 0 )
105 return mLines.at( index.row() );
108bool QgsListModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
113 if ( index.row() < 0 || index.row() >= mLines.count() || index.column() != 0 || role != Qt::EditRole )
117 mLines[index.row()] = value.toString();
118 emit dataChanged( index, index );
122Qt::ItemFlags QgsListModel::flags(
const QModelIndex &index )
const
125 return QAbstractTableModel::flags( index ) | Qt::ItemIsEditable;
127 return QAbstractTableModel::flags( index );
130bool QgsListModel::insertRows(
int position,
int rows,
const QModelIndex &parent )
136 beginInsertRows( QModelIndex(), position, position + rows - 1 );
137 for (
int i = 0; i < rows; ++i )
145bool QgsListModel::removeRows(
int position,
int rows,
const QModelIndex &parent )
151 beginRemoveRows( QModelIndex(), position, position + rows - 1 );
152 for (
int i = 0; i < rows; ++i )
153 mLines.removeAt( position );
158void QgsListModel::setReadOnly(
bool readOnly )
160 mReadOnly = readOnly;
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.