Skip to content
Permalink
Browse files

Remove some clutter in attribute table dialog by moving the

"organize fields" and "sort" actions from toolbar buttons
into a right-click menu on the column headings
  • Loading branch information
nyalldawson committed Jun 2, 2016
1 parent 6c6a177 commit 872bdd6284e9a3cd58421b2ed29d2878d63fd9a7
@@ -631,52 +631,6 @@ void QgsAttributeTableDialog::on_mAddFeature_clicked()
}
}

void QgsAttributeTableDialog::on_mSortButton_clicked()
{
QgsAttributeTableConfig config = mLayer->attributeTableConfig();

QDialog orderByDlg;
orderByDlg.setWindowTitle( tr( "Configure attribute table sort order" ) );
QDialogButtonBox* dialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
QGridLayout* layout = new QGridLayout();
connect( dialogButtonBox, SIGNAL( accepted() ), &orderByDlg, SLOT( accept() ) );
connect( dialogButtonBox, SIGNAL( rejected() ), &orderByDlg, SLOT( reject() ) );
orderByDlg.setLayout( layout );

QGroupBox* sortingGroupBox = new QGroupBox();
sortingGroupBox->setTitle( tr( "Enable sorting order in attribute table" ) );
sortingGroupBox->setCheckable( true );
sortingGroupBox->setChecked( !mMainView->sortExpression().isEmpty() );
layout->addWidget( sortingGroupBox );
sortingGroupBox->setLayout( new QGridLayout() );

QgsExpressionBuilderWidget* expressionBuilder = new QgsExpressionBuilderWidget();
expressionBuilder->setExpressionText( mMainView->sortExpression().isEmpty() ? mLayer->displayExpression() : mMainView->sortExpression() );
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope();
expressionBuilder->setExpressionContext( context );
expressionBuilder->setLayer( mLayer );
sortingGroupBox->layout()->addWidget( expressionBuilder );

layout->addWidget( dialogButtonBox );
if ( orderByDlg.exec() )
{
if ( sortingGroupBox->isChecked() )
{
mMainView->setSortExpression( expressionBuilder->expressionText() );
config.setSortExpression( expressionBuilder->expressionText() );
}
else
{
mMainView->setSortExpression( QString() );
config.setSortExpression( QString() );
}

mLayer->setAttributeTableConfig( config );
}
}

void QgsAttributeTableDialog::on_mExpressionSelectButton_clicked()
{
QgsExpressionSelectionDialog* dlg = new QgsExpressionSelectionDialog( mLayer );
@@ -838,22 +792,6 @@ void QgsAttributeTableDialog::on_mRemoveAttribute_clicked()
}
}

void QgsAttributeTableDialog::on_mFilterTableFields_clicked()
{
if ( !mLayer )
{
return;
}

QgsOrganizeTableColumnsDialog dialog( mLayer, this );
if ( dialog.exec() == QDialog::Accepted )
{
QgsAttributeTableConfig config = dialog.config();
mLayer->setAttributeTableConfig( config );
mMainView->setAttributeTableConfig( config );
}
}

void QgsAttributeTableDialog::filterQueryChanged( const QString& query )
{
QString str;
@@ -91,11 +91,6 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
* Reload the data
*/
void on_mReloadButton_clicked();
/**
* Filter the columns (open a dialog, ...)
*/
void on_mFilterTableFields_clicked();

/**
* Inverts selection
*/
@@ -156,8 +151,6 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib

void on_mHelpButton_clicked() { QgsContextHelp::run( metaObject()->className() ); }

void on_mSortButton_clicked();

void on_mExpressionSelectButton_clicked();
void filterColumnChanged( QObject* filterAction );
void filterExpressionBuilder();
@@ -25,13 +25,15 @@
#include "qgsmessagelog.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayercache.h"
#include "qgsorganizetablecolumnsdialog.h"

#include <QClipboard>
#include <QDialog>
#include <QMenu>
#include <QMessageBox>
#include <QProgressDialog>
#include <QSettings>
#include <QGroupBox>

QgsDualView::QgsDualView( QWidget* parent )
: QStackedWidget( parent )
@@ -40,6 +42,7 @@ QgsDualView::QgsDualView( QWidget* parent )
, mFilterModel( nullptr )
, mFeatureListModel( nullptr )
, mAttributeForm( nullptr )
, mHorizontalHeaderMenu( nullptr )
, mLayerCache( nullptr )
, mProgressDlg( nullptr )
, mFeatureSelectionManager( nullptr )
@@ -67,6 +70,8 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
mEditorContext = context;

connect( mTableView, SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ), this, SLOT( viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
mTableView->horizontalHeader()->setContextMenuPolicy( Qt::CustomContextMenu );
connect( mTableView->horizontalHeader(), SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( showViewHeaderMenu( QPoint ) ) );

initLayerCache( layer, !request.filterRect().isNull() );
initModels( mapCanvas, request );
@@ -453,6 +458,89 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
menu->addAction( tr( "Open form" ), a, SLOT( featureForm() ) );
}

void QgsDualView::showViewHeaderMenu( QPoint point )
{
delete mHorizontalHeaderMenu;
mHorizontalHeaderMenu = new QMenu( this );
QAction* organize = new QAction( tr( "&Organize columns..." ), mHorizontalHeaderMenu );
connect( organize, SIGNAL( triggered( bool ) ), this, SLOT( organizeColumns() ) );
mHorizontalHeaderMenu->addAction( organize );
QAction* sort = new QAction( tr( "&Sort..." ), mHorizontalHeaderMenu );
connect( sort, SIGNAL( triggered( bool ) ), this, SLOT( modifySort() ) );
mHorizontalHeaderMenu->addAction( sort );
mHorizontalHeaderMenu->popup( mTableView->horizontalHeader()->mapToGlobal( point ) );
}

void QgsDualView::organizeColumns()
{
if ( !mLayerCache->layer() )
{
return;
}

QgsOrganizeTableColumnsDialog dialog( mLayerCache->layer(), this );
if ( dialog.exec() == QDialog::Accepted )
{
QgsAttributeTableConfig config = dialog.config();
mLayerCache->layer()->setAttributeTableConfig( config );
setAttributeTableConfig( config );
}
}

void QgsDualView::modifySort()
{
QgsVectorLayer* layer = mLayerCache->layer();
if ( !layer )
return;

QgsAttributeTableConfig config = layer->attributeTableConfig();

QDialog orderByDlg;
orderByDlg.setWindowTitle( tr( "Configure attribute table sort order" ) );
QDialogButtonBox* dialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
QGridLayout* layout = new QGridLayout();
connect( dialogButtonBox, SIGNAL( accepted() ), &orderByDlg, SLOT( accept() ) );
connect( dialogButtonBox, SIGNAL( rejected() ), &orderByDlg, SLOT( reject() ) );
orderByDlg.setLayout( layout );

QGroupBox* sortingGroupBox = new QGroupBox();
sortingGroupBox->setTitle( tr( "Enable sorting order in attribute table" ) );
sortingGroupBox->setCheckable( true );
sortingGroupBox->setChecked( !sortExpression().isEmpty() );
layout->addWidget( sortingGroupBox );
sortingGroupBox->setLayout( new QGridLayout() );

QgsExpressionBuilderWidget* expressionBuilder = new QgsExpressionBuilderWidget();
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( layer );
expressionBuilder->setExpressionContext( context );
expressionBuilder->setLayer( layer );
expressionBuilder->loadFieldNames();
expressionBuilder->loadRecent( "generic" );
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? layer->displayExpression() : sortExpression() );

sortingGroupBox->layout()->addWidget( expressionBuilder );

layout->addWidget( dialogButtonBox );
if ( orderByDlg.exec() )
{
if ( sortingGroupBox->isChecked() )
{
setSortExpression( expressionBuilder->expressionText() );
config.setSortExpression( expressionBuilder->expressionText() );
}
else
{
setSortExpression( QString() );
config.setSortExpression( QString() );
}

layer->setAttributeTableConfig( config );
}
}

void QgsDualView::zoomToCurrentFeature()
{
QModelIndex currentIndex = mTableView->currentIndex();
@@ -273,6 +273,12 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas

void viewWillShowContextMenu( QMenu* menu, const QModelIndex& atIndex );

void showViewHeaderMenu( QPoint point );

void organizeColumns();

void modifySort();

void previewExpressionChanged( const QString& expression );

void sortByPreviewExpression();
@@ -312,6 +318,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
QgsAttributeForm* mAttributeForm;
QSignalMapper* mPreviewActionMapper;
QMenu* mPreviewColumnsMenu;
QMenu* mHorizontalHeaderMenu;
QgsVectorLayerCache* mLayerCache;
QProgressDialog* mProgressDlg;
QgsIFeatureSelectionManager* mFeatureSelectionManager;
@@ -581,52 +581,6 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mFilterTableFields">
<property name="toolTip">
<string>Organize table columns</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFilterTableFields.svg</normaloff>:/images/themes/default/mActionFilterTableFields.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mSortButton">
<property name="toolTip">
<string>Control the sort order</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/sort.svg</normaloff>:/images/themes/default/sort.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

0 comments on commit 872bdd6

Please sign in to comment.
You can’t perform that action at this time.