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 ),
47void QgsListModel::setList(
const QVariantList &list )
54QVariantList QgsListModel::list()
const
57 for ( QVariantList::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
60 if ( cur.convert( mSubType ) )
66bool QgsListModel::valid()
const
68 for ( QVariantList::const_iterator it = mLines.constBegin(); it != mLines.constEnd(); ++it )
71 if ( !cur.convert( mSubType ) )
return false;
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 ||
100 index.row() >= mLines.count() ||
101 ( role != Qt::DisplayRole && role != Qt::EditRole ) ||
102 index.column() != 0 )
106 return mLines.at( index.row() );
109bool QgsListModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
114 if ( index.row() < 0 || index.row() >= mLines.count() ||
115 index.column() != 0 || role != Qt::EditRole )
119 mLines[index.row()] = value.toString();
120 emit dataChanged( index, index );
124Qt::ItemFlags QgsListModel::flags(
const QModelIndex &index )
const
127 return QAbstractTableModel::flags( index ) | Qt::ItemIsEditable;
129 return QAbstractTableModel::flags( index );
132bool QgsListModel::insertRows(
int position,
int rows,
const QModelIndex &parent )
138 beginInsertRows( QModelIndex(), position, position + rows - 1 );
139 for (
int i = 0; i < rows; ++i )
147bool QgsListModel::removeRows(
int position,
int rows,
const QModelIndex &parent )
153 beginRemoveRows( QModelIndex(), position, position + rows - 1 );
154 for (
int i = 0; i < rows; ++i )
155 mLines.removeAt( position );
160void QgsListModel::setReadOnly(
bool readOnly )
162 mReadOnly = readOnly;
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.