36 : QAbstractTableModel( parent )
37 , mLayerCache( layerCache )
49 if ( !
layer()->hasGeometryType() )
89 beginRemoveRows( QModelIndex(), row, row );
101 for (
int i = row; i < row + count; i++ )
109 for (
int i = row + count; i < n; i++ )
120 for ( QHash<QgsFeatureId, int>::iterator it =
mIdRowMap.begin(); it !=
mIdRowMap.end(); ++it )
123 QHash<QgsFeatureId, int>::iterator idit;
126 for ( QHash<int, QgsFeatureId>::iterator it =
mRowIdMap.begin(); it !=
mRowIdMap.end(); ++it )
148 beginInsertRows( QModelIndex(), n, n );
186 beginRemoveRows( QModelIndex(), 0,
rowCount() - 1 );
190 const QMap<QString, QVariant> *item;
246 bool ins =
false, rm =
false;
250 for (
int idx = 0; idx < fields.
count(); ++idx )
258 mValueMaps.insert( idx,
new QMap< QString, QVariant >(
layer()->valueMap( idx ) ) );
280 if ( ki >= 0 && vi >= 0 )
282 QSet<int> attributes;
283 attributes << ki << vi;
301 QMap< QString, QVariant > *map =
new QMap< QString, QVariant >();
305 while ( fit.nextFeature( f ) )
307 if ( e && !e->
evaluate( &f ).toBool() )
328 beginInsertColumns( QModelIndex(),
mFieldCount, attributes.size() - 1 );
333 beginRemoveColumns( QModelIndex(), attributes.size(),
mFieldCount - 1 );
353 beginRemoveRows( QModelIndex(), 0,
rowCount() - 1 );
369 if ( t.elapsed() > 1000 )
414 QgsDebugMsg( QString(
"idToRow: id %1 not in the map" ).arg(
id ) );
428 QModelIndexList indexes;
431 for (
int column = 0; column <
columnCount(); ++column )
433 indexes.append(
index( row, column ) );
443 QgsDebugMsg( QString(
"rowToId: row %1 not in the map" ).arg( row ) );
478 if ( role == Qt::DisplayRole )
480 if ( orientation == Qt::Vertical )
482 return QVariant( section );
487 if ( attributeName.isEmpty() )
490 attributeName = field.
name();
492 return QVariant( attributeName );
496 return tr(
"feature id" );
507 if ( !index.isValid() ||
508 ( role != Qt::TextAlignmentRole
509 && role != Qt::DisplayRole
510 && role != Qt::EditRole
524 return role == Qt::DisplayRole ? rowId : QVariant();
533 QVariant::Type fldType = field.
type();
534 bool fldNumeric = ( fldType == QVariant::Int || fldType == QVariant::Double );
536 if ( role == Qt::TextAlignmentRole )
539 return QVariant( Qt::AlignRight );
541 return QVariant( Qt::AlignLeft );
556 return QVariant(
"ERROR" );
559 return QVariant(
"ERROR" );
574 if ( role == Qt::EditRole )
576 return QVariant( fldType );
581 return settings.value(
"qgis/nullValue",
"NULL" );
585 if ( role == Qt::DisplayRole )
589 return mValueMaps[ fieldId ]->key( val.toString(), QString(
"(%1)" ).arg( val.toString() ) );
594 return val.toDate().toString(
layer()->dateFormat( fieldId ) );
641 if ( !index.isValid() )
642 return Qt::ItemIsEnabled;
645 return Qt::NoItemFlags;
649 if (
layer()->isEditable() &&
651 flags |= Qt::ItemIsEditable;
659 emit dataChanged( index1, index2 );
706 QStringList fldNames;
707 fldNames << fields[ fieldId ].name();