33 : mCurrentSortColumn( 0 ), mAscending( true )
40 QVariant v1 = m1[mCurrentSortColumn];
41 QVariant v2 = m2[mCurrentSortColumn];
46 if ( v1.isNull() && v2.isNull() )
50 else if ( v1.isNull() )
54 else if ( v2.isNull() )
65 case QVariant::LongLong:
66 case QVariant::ULongLong:
67 less = v1.toLongLong() < v2.toLongLong();
70 case QVariant::Double:
71 less = v1.toDouble() < v2.toDouble();
75 less = v1.toDate() < v2.toDate();
78 case QVariant::DateTime:
79 less = v1.toDateTime() < v2.toDateTime();
83 less = v1.toTime() < v2.toTime();
88 less = v1.toString().localeAwareCompare( v2.toString() ) < 0;
93 return ( mAscending ? less : !less );
102 , mSource( LayerAttributes )
104 , mCurrentAtlasLayer( 0 )
106 , mMaximumNumberOfFeatures( 30 )
107 , mShowUniqueRowsOnly( false )
108 , mShowOnlyVisibleFeatures( false )
109 , mFilterToAtlasIntersection( false )
110 , mFilterFeatures( false )
111 , mFeatureFilter(
"" )
115 QMap<QString, QgsMapLayer*>::const_iterator mapIt = layerMap.constBegin();
116 for ( ; mapIt != layerMap.constEnd(); ++mapIt )
129 connect( mVectorLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
153 return tr(
"<attribute table>" );
158 if ( layer == mVectorLayer )
165 mVectorLayer = layer;
172 disconnect( prevLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
179 connect( mVectorLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
188 if ( relationId == mRelationId )
204 disconnect( prevLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
211 connect( newLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
218 void QgsComposerAttributeTableV2::atlasLayerChanged(
QgsVectorLayer *layer )
227 if ( mCurrentAtlasLayer )
230 disconnect( mCurrentAtlasLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
233 mCurrentAtlasLayer = layer;
257 for (
int idx = 0; idx < fields.
count(); ++idx )
269 if ( map == mComposerMap )
278 disconnect( mComposerMap, SIGNAL( extentChanged() ),
this, SLOT(
refreshAttributes() ) );
284 connect( mComposerMap, SIGNAL( extentChanged() ),
this, SLOT(
refreshAttributes() ) );
292 if ( features == mMaximumNumberOfFeatures )
297 mMaximumNumberOfFeatures = features;
304 if ( uniqueOnly == mShowUniqueRowsOnly )
309 mShowUniqueRowsOnly = uniqueOnly;
316 if ( visibleOnly == mShowOnlyVisibleFeatures )
321 mShowOnlyVisibleFeatures = visibleOnly;
328 if ( filterToAtlas == mFilterToAtlasIntersection )
333 mFilterToAtlasIntersection = filterToAtlas;
340 if ( filter == mFilterFeatures )
345 mFilterFeatures = filter;
352 if ( expression == mFeatureFilter )
357 mFeatureFilter = expression;
378 QSet<int>::const_iterator attIt = attr.constBegin();
379 for ( ; attIt != attr.constEnd(); ++attIt )
381 int attrIdx = ( *attIt );
382 if ( !fields.
exists( attrIdx ) )
396 for (
int idx = 0; idx < fields.
count(); ++idx )
412 void QgsComposerAttributeTableV2::restoreFieldAliasMap(
const QMap<int, QString>& map )
420 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
421 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
423 int attrIdx = source->
fieldNameIndex(( *columnIt )->attribute() );
424 if ( map.contains( attrIdx ) )
426 ( *columnIt )->setHeading( map.value( attrIdx ) );
455 QScopedPointer<QgsExpression> filterExpression;
456 bool activeFilter =
false;
457 if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
459 filterExpression.reset(
new QgsExpression( mFeatureFilter ) );
460 if ( !filterExpression->hasParserError() )
467 if ( mComposerMap && mShowOnlyVisibleFeatures )
503 if ( !selectionRect.
isEmpty() )
528 while ( fit.
nextFeature( f ) && counter < mMaximumNumberOfFeatures )
531 if ( activeFilter && !filterExpression.isNull() )
533 QVariant result = filterExpression->evaluate( &f, layer->
pendingFields() );
535 if ( !result.toBool() )
541 if ( mFilterToAtlasIntersection )
548 if ( !atlasFeature || !atlasFeature->
geometry() ||
558 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
559 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
572 QVariant value = expression->
evaluate( f );
579 contents << currentRow;
587 for (
int i = sortColumns.size() - 1; i >= 0; --i )
591 qStableSort( contents.begin(), contents.end(), c );
615 void QgsComposerAttributeTableV2::removeLayer( QString layerId )
619 if ( layerId == mVectorLayer->
id() )
629 static bool columnsBySortRank( QPair<int, QgsComposerTableColumn* > a, QPair<int, QgsComposerTableColumn* > b )
631 return a.second->sortByRank() < b.second->sortByRank();
637 QList< QPair<int, QgsComposerTableColumn* > > sortedColumns;
638 QList<QgsComposerTableColumn*>::const_iterator columnIt =
mColumns.constBegin();
640 for ( ; columnIt !=
mColumns.constEnd(); ++columnIt )
642 if (( *columnIt )->sortByRank() > 0 )
644 sortedColumns.append( qMakePair( idx, *columnIt ) );
653 QList<QPair<int, bool> > attributesBySortRank;
654 QList< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
655 for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
658 attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
659 ( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
661 return attributesBySortRank;
666 QDomElement composerTableElem = doc.createElement(
"ComposerAttributeTableV2" );
667 composerTableElem.setAttribute(
"source", QString::number((
int )mSource ) );
668 composerTableElem.setAttribute(
"relationId", mRelationId );
669 composerTableElem.setAttribute(
"showUniqueRowsOnly", mShowUniqueRowsOnly );
670 composerTableElem.setAttribute(
"showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
671 composerTableElem.setAttribute(
"filterToAtlasIntersection", mFilterToAtlasIntersection );
672 composerTableElem.setAttribute(
"maxFeatures", mMaximumNumberOfFeatures );
673 composerTableElem.setAttribute(
"filterFeatures", mFilterFeatures ?
"true" :
"false" );
674 composerTableElem.setAttribute(
"featureFilter", mFeatureFilter );
678 composerTableElem.setAttribute(
"composerMap", mComposerMap->
id() );
682 composerTableElem.setAttribute(
"composerMap", -1 );
686 composerTableElem.setAttribute(
"vectorLayer", mVectorLayer->
id() );
691 elem.appendChild( composerTableElem );
698 if ( itemElem.isNull() )
713 disconnect( prevLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
717 mRelationId = itemElem.attribute(
"relationId",
"" );
724 mShowUniqueRowsOnly = itemElem.attribute(
"showUniqueRowsOnly",
"0" ).toInt();
725 mShowOnlyVisibleFeatures = itemElem.attribute(
"showOnlyVisibleFeatures",
"1" ).toInt();
726 mFilterToAtlasIntersection = itemElem.attribute(
"filterToAtlasIntersection",
"0" ).toInt();
727 mFilterFeatures = itemElem.attribute(
"filterFeatures",
"false" ) ==
"true" ?
true :
false;
728 mFeatureFilter = itemElem.attribute(
"featureFilter",
"" );
729 mMaximumNumberOfFeatures = itemElem.attribute(
"maxFeatures",
"5" ).toInt();
732 int composerMapId = itemElem.attribute(
"composerMap",
"-1" ).toInt();
733 if ( composerMapId == -1 )
750 connect( mComposerMap, SIGNAL( extentChanged() ),
this, SLOT(
refreshAttributes() ) );
754 QString layerId = itemElem.attribute(
"vectorLayer",
"not_existing" );
755 if ( layerId ==
"not_existing" )
786 if ( recalcFrameSizes )
794 if ( source == mSource )
803 if ( newLayer != prevLayer )
808 disconnect( prevLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
812 connect( newLayer, SIGNAL( layerModified() ),
this, SLOT(
refreshAttributes() ) );
815 mCurrentAtlasLayer = newLayer;