mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
parent
febcabb0da
commit
b83aab7d74
@ -154,4 +154,16 @@ class QgsAttributeTableConfig
|
||||
* @see columnHidden()
|
||||
*/
|
||||
void setColumnHidden( int column, bool hidden );
|
||||
|
||||
/**
|
||||
* Get the sort order
|
||||
* @note Added in 2.16
|
||||
*/
|
||||
Qt::SortOrder sortOrder() const;
|
||||
|
||||
/**
|
||||
* Set the sort order
|
||||
* @note Added in 2.16
|
||||
*/
|
||||
void setSortOrder( const Qt::SortOrder& sortOrder );
|
||||
};
|
||||
|
@ -135,6 +135,7 @@ class QgsDualView : QStackedWidget
|
||||
* @return The table view
|
||||
*/
|
||||
QgsAttributeTableView* tableView();
|
||||
|
||||
/**
|
||||
* Set the attribute table config which should be used to control
|
||||
* the appearance of the attribute table.
|
||||
@ -144,7 +145,7 @@ class QgsDualView : QStackedWidget
|
||||
/**
|
||||
* Set the expression used for sorting the table and feature list.
|
||||
*/
|
||||
void setSortExpression( const QString& sortExpression );
|
||||
void setSortExpression( const QString& sortExpression , Qt::SortOrder sortOrder = Qt::AscendingOrder );
|
||||
|
||||
/**
|
||||
* Get the expression used for sorting the table and feature list.
|
||||
|
@ -196,6 +196,7 @@ void QgsAttributeTableConfig::readXml( const QDomNode& node )
|
||||
}
|
||||
|
||||
mSortExpression = configNode.toElement().attribute( "sortExpression" );
|
||||
mSortOrder = static_cast<Qt::SortOrder>( configNode.toElement().attribute( "sortOrder" ).toInt() );
|
||||
}
|
||||
|
||||
QString QgsAttributeTableConfig::sortExpression() const
|
||||
@ -230,7 +231,17 @@ void QgsAttributeTableConfig::setColumnHidden( int column, bool hidden )
|
||||
|
||||
bool QgsAttributeTableConfig::operator!=( const QgsAttributeTableConfig& other ) const
|
||||
{
|
||||
return mSortExpression != other.mSortExpression || mColumns != other.mColumns || mActionWidgetStyle != other.mActionWidgetStyle;
|
||||
return mSortExpression != other.mSortExpression || mColumns != other.mColumns || mActionWidgetStyle != other.mActionWidgetStyle || mSortOrder != other.mSortOrder;
|
||||
}
|
||||
|
||||
Qt::SortOrder QgsAttributeTableConfig::sortOrder() const
|
||||
{
|
||||
return mSortOrder;
|
||||
}
|
||||
|
||||
void QgsAttributeTableConfig::setSortOrder( const Qt::SortOrder& sortOrder )
|
||||
{
|
||||
mSortOrder = sortOrder;
|
||||
}
|
||||
|
||||
void QgsAttributeTableConfig::writeXml( QDomNode& node ) const
|
||||
@ -242,6 +253,8 @@ void QgsAttributeTableConfig::writeXml( QDomNode& node ) const
|
||||
|
||||
configElement.setAttribute( "sortExpression", mSortExpression );
|
||||
|
||||
configElement.setAttribute( "sortOrder", mSortOrder );
|
||||
|
||||
QDomElement columnsElement = doc.createElement( "columns" );
|
||||
|
||||
Q_FOREACH ( const ColumnConfig& column, mColumns )
|
||||
|
@ -167,6 +167,18 @@ class CORE_EXPORT QgsAttributeTableConfig
|
||||
*/
|
||||
void setColumnHidden( int column, bool hidden );
|
||||
|
||||
/**
|
||||
* Get the sort order
|
||||
* @note Added in 2.16
|
||||
*/
|
||||
Qt::SortOrder sortOrder() const;
|
||||
|
||||
/**
|
||||
* Set the sort order
|
||||
* @note Added in 2.16
|
||||
*/
|
||||
void setSortOrder( const Qt::SortOrder& sortOrder );
|
||||
|
||||
/**
|
||||
* Compare this configuration to other.
|
||||
*/
|
||||
@ -176,6 +188,7 @@ class CORE_EXPORT QgsAttributeTableConfig
|
||||
QVector<ColumnConfig> mColumns;
|
||||
ActionWidgetStyle mActionWidgetStyle;
|
||||
QString mSortExpression;
|
||||
Qt::SortOrder mSortOrder;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE( QgsAttributeTableConfig::ColumnConfig )
|
||||
|
@ -205,7 +205,7 @@ void QgsAttributeTableFilterModel::setAttributeTableConfig( const QgsAttributeTa
|
||||
}
|
||||
}
|
||||
|
||||
sort( config.sortExpression() );
|
||||
sort( config.sortExpression(), config.sortOrder() );
|
||||
}
|
||||
|
||||
void QgsAttributeTableFilterModel::sort( QString expression, Qt::SortOrder order )
|
||||
|
@ -591,7 +591,7 @@ void QgsDualView::modifySort()
|
||||
orderByDlg.setLayout( layout );
|
||||
|
||||
QGroupBox* sortingGroupBox = new QGroupBox();
|
||||
sortingGroupBox->setTitle( tr( "Enable sorting order in attribute table" ) );
|
||||
sortingGroupBox->setTitle( tr( "Defined sort order in attribute table" ) );
|
||||
sortingGroupBox->setCheckable( true );
|
||||
sortingGroupBox->setChecked( !sortExpression().isEmpty() );
|
||||
layout->addWidget( sortingGroupBox );
|
||||
@ -610,22 +610,27 @@ void QgsDualView::modifySort()
|
||||
|
||||
sortingGroupBox->layout()->addWidget( expressionBuilder );
|
||||
|
||||
QCheckBox* cbxSortAscending = new QCheckBox( tr( "Sort ascending" ) );
|
||||
cbxSortAscending->setChecked( config.sortOrder() == Qt::AscendingOrder );
|
||||
sortingGroupBox->layout()->addWidget( cbxSortAscending );
|
||||
|
||||
layout->addWidget( dialogButtonBox );
|
||||
if ( orderByDlg.exec() )
|
||||
{
|
||||
Qt::SortOrder sortOrder = cbxSortAscending->isChecked() ? Qt::AscendingOrder : Qt::DescendingOrder;
|
||||
if ( sortingGroupBox->isChecked() )
|
||||
{
|
||||
setSortExpression( expressionBuilder->expressionText() );
|
||||
setSortExpression( expressionBuilder->expressionText(), sortOrder );
|
||||
config.setSortExpression( expressionBuilder->expressionText() );
|
||||
config.setSortOrder( sortOrder );
|
||||
}
|
||||
else
|
||||
{
|
||||
setSortExpression( QString() );
|
||||
setSortExpression( QString(), sortOrder );
|
||||
config.setSortExpression( QString() );
|
||||
}
|
||||
|
||||
layer->setAttributeTableConfig( config );
|
||||
mConfig = config;
|
||||
setAttributeTableConfig( config );
|
||||
}
|
||||
}
|
||||
|
||||
@ -655,12 +660,18 @@ void QgsDualView::onSortColumnChanged()
|
||||
{
|
||||
QgsAttributeTableConfig cfg = mLayerCache->layer()->attributeTableConfig();
|
||||
cfg.setSortExpression( mFilterModel->sortExpression() );
|
||||
cfg.setSortOrder( mFilterModel->sortOrder() );
|
||||
mLayerCache->layer()->setAttributeTableConfig( cfg );
|
||||
}
|
||||
|
||||
void QgsDualView::sortByPreviewExpression()
|
||||
{
|
||||
setSortExpression( mFeatureList->displayExpression() );
|
||||
Qt::SortOrder sortOrder = Qt::AscendingOrder;
|
||||
if ( mFeatureList->displayExpression() == sortExpression() )
|
||||
{
|
||||
sortOrder = mConfig.sortOrder() == Qt::AscendingOrder ? Qt::DescendingOrder : Qt::AscendingOrder;
|
||||
}
|
||||
setSortExpression( mFeatureList->displayExpression(), sortOrder );
|
||||
}
|
||||
|
||||
void QgsDualView::featureFormAttributeChanged()
|
||||
@ -697,16 +708,16 @@ void QgsDualView::setAttributeTableConfig( const QgsAttributeTableConfig& config
|
||||
mConfig = config;
|
||||
}
|
||||
|
||||
void QgsDualView::setSortExpression( const QString& sortExpression )
|
||||
void QgsDualView::setSortExpression( const QString& sortExpression, Qt::SortOrder sortOrder )
|
||||
{
|
||||
if ( sortExpression.isNull() )
|
||||
mFilterModel->sort( -1 );
|
||||
else
|
||||
mFilterModel->sort( sortExpression );
|
||||
mFilterModel->sort( sortExpression, sortOrder );
|
||||
|
||||
QgsAttributeTableConfig cfg = mLayerCache->layer()->attributeTableConfig();
|
||||
cfg.setSortExpression( sortExpression );
|
||||
mLayerCache->layer()->setAttributeTableConfig( cfg );
|
||||
mConfig.setSortExpression( sortExpression );
|
||||
mConfig.setSortOrder( sortOrder );
|
||||
mLayerCache->layer()->setAttributeTableConfig( mConfig );
|
||||
}
|
||||
|
||||
QString QgsDualView::sortExpression() const
|
||||
|
@ -185,7 +185,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
|
||||
/**
|
||||
* Set the expression used for sorting the table and feature list.
|
||||
*/
|
||||
void setSortExpression( const QString& sortExpression );
|
||||
void setSortExpression( const QString& sortExpression , Qt::SortOrder sortOrder = Qt::AscendingOrder );
|
||||
|
||||
/**
|
||||
* Get the expression used for sorting the table and feature list.
|
||||
|
Loading…
x
Reference in New Issue
Block a user