17#include "moc_qgslistwidget.cpp"
22 , mModel( subType, this )
29 removeButton->setEnabled(
false );
30 mModel.setList(
list );
35 mModel.setReadOnly( readOnly );
41QgsListModel::QgsListModel( QMetaType::Type subType, QObject *parent )
42 : QAbstractTableModel( parent ), mSubType( subType )
46void QgsListModel::setList(
const QVariantList &list )
53QVariantList QgsListModel::list()
const
56 for ( QVariantList::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
59 if ( cur.convert( mSubType ) )
65bool QgsListModel::valid()
const
67 for ( QVariantList::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
70 if ( !cur.convert( mSubType ) )
76int QgsListModel::rowCount(
const QModelIndex &parent )
const
79 return mLines.count();
82int QgsListModel::columnCount(
const QModelIndex &parent )
const
88QVariant QgsListModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
90 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0 )
92 return QObject::tr(
"Value" );
97QVariant QgsListModel::data(
const QModelIndex &index,
int role )
const
99 if ( index.row() < 0 || index.row() >= mLines.count() || ( role != Qt::DisplayRole && role != Qt::EditRole ) || index.column() != 0 )
103 return mLines.at( index.row() );
106bool QgsListModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
111 if ( index.row() < 0 || index.row() >= mLines.count() || index.column() != 0 || role != Qt::EditRole )
115 mLines[index.row()] = value.toString();
116 emit dataChanged( index, index );
120Qt::ItemFlags QgsListModel::flags(
const QModelIndex &index )
const
123 return QAbstractTableModel::flags( index ) | Qt::ItemIsEditable;
125 return QAbstractTableModel::flags( index );
128bool QgsListModel::insertRows(
int position,
int rows,
const QModelIndex &parent )
134 beginInsertRows( QModelIndex(), position, position + rows - 1 );
135 for (
int i = 0; i < rows; ++i )
143bool QgsListModel::removeRows(
int position,
int rows,
const QModelIndex &parent )
149 beginRemoveRows( QModelIndex(), position, position + rows - 1 );
150 for (
int i = 0; i < rows; ++i )
151 mLines.removeAt( position );
156void QgsListModel::setReadOnly(
bool readOnly )
158 mReadOnly = readOnly;
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.