35 : QAbstractTableModel( parent )
36 , mLayerCache( layerCache )
48 if ( !
layer()->hasGeometryType() )
84 beginRemoveRows( QModelIndex(), row, row );
95 for (
int i = row; i < row + count; i++ )
103 for (
int i = row + count; i < n; i++ )
114 for ( QHash<QgsFeatureId, int>::iterator it =
mIdRowMap.begin(); it !=
mIdRowMap.end(); ++it )
117 QHash<QgsFeatureId, int>::iterator idit;
120 for ( QHash<int, QgsFeatureId>::iterator it =
mRowIdMap.begin(); it !=
mRowIdMap.end(); ++it )
134 beginInsertRows( QModelIndex(), n, n );
164 beginRemoveRows( QModelIndex(), 0,
rowCount() - 1 );
168 const QMap<QString, QVariant> *item;
196 bool ins =
false, rm =
false;
200 for (
int idx = 0; idx < fields.
count(); ++idx )
208 mValueMaps.insert( idx,
new QMap< QString, QVariant >(
layer()->valueMap( idx ) ) );
230 if ( ki >= 0 && vi >= 0 )
232 QSet<int> attributes;
233 attributes << ki << vi;
251 QMap< QString, QVariant > *map =
new QMap< QString, QVariant >();
255 while ( fit.nextFeature( f ) )
257 if ( e && !e->
evaluate( &f ).toBool() )
278 beginInsertColumns( QModelIndex(),
mFieldCount, attributes.size() - 1 );
283 beginRemoveColumns( QModelIndex(), attributes.size(),
mFieldCount - 1 );
303 beginRemoveRows( QModelIndex(), 0,
rowCount() - 1 );
319 if ( t.elapsed() > 1000 )
363 QgsDebugMsg( QString(
"idToRow: id %1 not in the map" ).arg(
id ) );
372 return index(
idToRow(
id ), 0 );
377 QModelIndexList indexes;
380 for (
int column = 0; column <
columnCount(); ++column )
382 indexes.append( index( row, column ) );
392 QgsDebugMsg( QString(
"rowToId: row %1 not in the map" ).arg( row ) );
427 if ( role == Qt::DisplayRole )
429 if ( orientation == Qt::Vertical )
431 return QVariant( section );
436 if ( attributeName.isEmpty() )
439 attributeName = field.
name();
441 return QVariant( attributeName );
445 return tr(
"feature id" );
456 if ( !index.isValid() ||
457 ( role != Qt::TextAlignmentRole
458 && role != Qt::DisplayRole
459 && role != Qt::EditRole
473 return role == Qt::DisplayRole ? rowId : QVariant();
482 QVariant::Type fldType = field.
type();
483 bool fldNumeric = ( fldType == QVariant::Int || fldType == QVariant::Double );
485 if ( role == Qt::TextAlignmentRole )
488 return QVariant( Qt::AlignRight );
490 return QVariant( Qt::AlignLeft );
505 return QVariant(
"ERROR" );
508 return QVariant(
"ERROR" );
523 if ( role == Qt::EditRole )
525 return QVariant( fldType );
530 return settings.value(
"qgis/nullValue",
"NULL" );
534 if ( role == Qt::DisplayRole )
538 return mValueMaps[ fieldId ]->key( val.toString(), QString(
"(%1)" ).arg( val.toString() ) );
543 return val.toDate().toString(
layer()->dateFormat( fieldId ) );
561 emit dataChanged( index, index );
568 if ( !index.isValid() )
569 return Qt::ItemIsEnabled;
572 return Qt::NoItemFlags;
576 if (
layer()->isEditable() &&
578 flags |= Qt::ItemIsEditable;
585 for (
int row = index1.row(); row <= index2.row(); row++ )
592 emit dataChanged( index1, index2 );
631 QStringList fldNames;
632 fldNames << fields[ fieldId ].name();