mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Fix QgsComposerAttributeTableV2 setting displayed fields under qt5
Also don't run QgsComposerAttributeTable test when disable deprecated flag is set.
This commit is contained in:
parent
008310d91d
commit
eb3a34cc92
@ -12,6 +12,4 @@ PyQgsSpatialiteProvider
|
||||
PyQgsVirtualLayerDefinition
|
||||
PyQgsVirtualLayerProvider
|
||||
qgis_composermapgridtest
|
||||
qgis_composertabletest
|
||||
qgis_composertablev2test
|
||||
qgis_composerutils
|
||||
|
@ -236,9 +236,19 @@ class QgsComposerAttributeTableV2 : QgsComposerTableV2
|
||||
* @param refresh set to true to force the table to refetch features from its vector layer
|
||||
* and immediately update the display of the table. This may result in the table changing size
|
||||
* to accommodate the new displayed feature attributes.
|
||||
* @see displayAttributes
|
||||
* @deprecated use setDisplayedFields() instead
|
||||
*/
|
||||
void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
|
||||
void setDisplayAttributes( const QSet<int>& attr, bool refresh = true ) /Deprecated/;
|
||||
|
||||
/** Sets the attributes to display in the table.
|
||||
* @param fields list of fields names from the vector layer to show.
|
||||
* Set to an empty list to show all feature attributes.
|
||||
* @param refresh set to true to force the table to refetch features from its vector layer
|
||||
* and immediately update the display of the table. This may result in the table changing size
|
||||
* to accommodate the new displayed feature attributes.
|
||||
* @note added in QGIS 2.16
|
||||
*/
|
||||
void setDisplayedFields( const QStringList& fields, bool refresh = true );
|
||||
|
||||
/** Returns the attributes used to sort the table's features.
|
||||
* @returns a QList of integer/bool pairs, where the integer refers to the attribute index and
|
||||
|
@ -361,6 +361,56 @@ void QgsComposerAttributeTableV2::setDisplayAttributes( const QSet<int>& attr, b
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerAttributeTableV2::setDisplayedFields( const QStringList& fields, bool refresh )
|
||||
{
|
||||
QgsVectorLayer* source = sourceLayer();
|
||||
if ( !source )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//rebuild columns list, taking only fields contained in supplied list
|
||||
qDeleteAll( mColumns );
|
||||
mColumns.clear();
|
||||
|
||||
QgsFields layerFields = source->fields();
|
||||
|
||||
if ( !fields.isEmpty() )
|
||||
{
|
||||
Q_FOREACH ( const QString& field, fields )
|
||||
{
|
||||
int attrIdx = layerFields.fieldNameIndex( field );
|
||||
if ( attrIdx < 0 )
|
||||
continue;
|
||||
|
||||
QString currentAlias = source->attributeDisplayName( attrIdx );
|
||||
QgsComposerTableColumn* col = new QgsComposerTableColumn;
|
||||
col->setAttribute( layerFields.at( attrIdx ).name() );
|
||||
col->setHeading( currentAlias );
|
||||
mColumns.append( col );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//resetting, so add all attributes to columns
|
||||
int idx = 0;
|
||||
Q_FOREACH ( const QgsField& field, layerFields )
|
||||
{
|
||||
QString currentAlias = source->attributeDisplayName( idx );
|
||||
QgsComposerTableColumn* col = new QgsComposerTableColumn;
|
||||
col->setAttribute( field.name() );
|
||||
col->setHeading( currentAlias );
|
||||
mColumns.append( col );
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( refresh )
|
||||
{
|
||||
refreshAttributes();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerAttributeTableV2::restoreFieldAliasMap( const QMap<int, QString>& map )
|
||||
{
|
||||
QgsVectorLayer* source = sourceLayer();
|
||||
|
@ -258,9 +258,19 @@ class CORE_EXPORT QgsComposerAttributeTableV2: public QgsComposerTableV2
|
||||
* @param refresh set to true to force the table to refetch features from its vector layer
|
||||
* and immediately update the display of the table. This may result in the table changing size
|
||||
* to accommodate the new displayed feature attributes.
|
||||
* @see displayAttributes
|
||||
* @deprecated use setDisplayedFields() instead
|
||||
*/
|
||||
void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
|
||||
Q_DECL_DEPRECATED void setDisplayAttributes( const QSet<int>& attr, bool refresh = true );
|
||||
|
||||
/** Sets the attributes to display in the table.
|
||||
* @param fields list of fields names from the vector layer to show.
|
||||
* Set to an empty list to show all feature attributes.
|
||||
* @param refresh set to true to force the table to refetch features from its vector layer
|
||||
* and immediately update the display of the table. This may result in the table changing size
|
||||
* to accommodate the new displayed feature attributes.
|
||||
* @note added in QGIS 2.16
|
||||
*/
|
||||
void setDisplayedFields( const QStringList& fields, bool refresh = true );
|
||||
|
||||
/** Returns the attributes used to sort the table's features.
|
||||
* @returns a QList of integer/bool pairs, where the integer refers to the attribute index and
|
||||
|
@ -113,7 +113,9 @@ ADD_QGIS_TEST(composerpicturetest testqgscomposerpicture.cpp)
|
||||
ADD_QGIS_TEST(composerrotationtest testqgscomposerrotation.cpp)
|
||||
ADD_QGIS_TEST(composerscalebartest testqgscomposerscalebar.cpp )
|
||||
ADD_QGIS_TEST(composershapestest testqgscomposershapes.cpp)
|
||||
IF(NOT DISABLE_DEPRECATED)
|
||||
ADD_QGIS_TEST(composertabletest testqgscomposertable.cpp)
|
||||
ENDIF(NOT DISABLE_DEPRECATED)
|
||||
ADD_QGIS_TEST(composertablev2test testqgscomposertablev2.cpp)
|
||||
ADD_QGIS_TEST(composerutils testqgscomposerutils.cpp)
|
||||
ADD_QGIS_TEST(connectionpooltest testqgsconnectionpool.cpp)
|
||||
|
@ -255,9 +255,9 @@ void TestQgsComposerTableV2::attributeTableFilterFeatures()
|
||||
void TestQgsComposerTableV2::attributeTableSetAttributes()
|
||||
{
|
||||
//test subset of attributes in table
|
||||
QSet<int> attributes;
|
||||
attributes << 0 << 3 << 4;
|
||||
mComposerAttributeTable->setDisplayAttributes( attributes );
|
||||
QStringList attributes;
|
||||
attributes << "Class" << "Pilots" << "Cabin Crew";
|
||||
mComposerAttributeTable->setDisplayedFields( attributes );
|
||||
mComposerAttributeTable->setMaximumNumberOfFeatures( 3 );
|
||||
|
||||
//check headers
|
||||
@ -291,7 +291,7 @@ void TestQgsComposerTableV2::attributeTableSetAttributes()
|
||||
compareTable( expectedRows );
|
||||
|
||||
attributes.clear();
|
||||
mComposerAttributeTable->setDisplayAttributes( attributes );
|
||||
mComposerAttributeTable->setDisplayedFields( attributes );
|
||||
}
|
||||
|
||||
void TestQgsComposerTableV2::attributeTableVisibleOnly()
|
||||
|
Loading…
x
Reference in New Issue
Block a user