Skip to content

Commit 872bdd6

Browse files
committed
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
1 parent 6c6a177 commit 872bdd6

5 files changed

+95
-115
lines changed

src/app/qgsattributetabledialog.cpp

-62
Original file line numberDiff line numberDiff line change
@@ -631,52 +631,6 @@ void QgsAttributeTableDialog::on_mAddFeature_clicked()
631631
}
632632
}
633633

634-
void QgsAttributeTableDialog::on_mSortButton_clicked()
635-
{
636-
QgsAttributeTableConfig config = mLayer->attributeTableConfig();
637-
638-
QDialog orderByDlg;
639-
orderByDlg.setWindowTitle( tr( "Configure attribute table sort order" ) );
640-
QDialogButtonBox* dialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
641-
QGridLayout* layout = new QGridLayout();
642-
connect( dialogButtonBox, SIGNAL( accepted() ), &orderByDlg, SLOT( accept() ) );
643-
connect( dialogButtonBox, SIGNAL( rejected() ), &orderByDlg, SLOT( reject() ) );
644-
orderByDlg.setLayout( layout );
645-
646-
QGroupBox* sortingGroupBox = new QGroupBox();
647-
sortingGroupBox->setTitle( tr( "Enable sorting order in attribute table" ) );
648-
sortingGroupBox->setCheckable( true );
649-
sortingGroupBox->setChecked( !mMainView->sortExpression().isEmpty() );
650-
layout->addWidget( sortingGroupBox );
651-
sortingGroupBox->setLayout( new QGridLayout() );
652-
653-
QgsExpressionBuilderWidget* expressionBuilder = new QgsExpressionBuilderWidget();
654-
expressionBuilder->setExpressionText( mMainView->sortExpression().isEmpty() ? mLayer->displayExpression() : mMainView->sortExpression() );
655-
QgsExpressionContext context;
656-
context << QgsExpressionContextUtils::globalScope()
657-
<< QgsExpressionContextUtils::projectScope();
658-
expressionBuilder->setExpressionContext( context );
659-
expressionBuilder->setLayer( mLayer );
660-
sortingGroupBox->layout()->addWidget( expressionBuilder );
661-
662-
layout->addWidget( dialogButtonBox );
663-
if ( orderByDlg.exec() )
664-
{
665-
if ( sortingGroupBox->isChecked() )
666-
{
667-
mMainView->setSortExpression( expressionBuilder->expressionText() );
668-
config.setSortExpression( expressionBuilder->expressionText() );
669-
}
670-
else
671-
{
672-
mMainView->setSortExpression( QString() );
673-
config.setSortExpression( QString() );
674-
}
675-
676-
mLayer->setAttributeTableConfig( config );
677-
}
678-
}
679-
680634
void QgsAttributeTableDialog::on_mExpressionSelectButton_clicked()
681635
{
682636
QgsExpressionSelectionDialog* dlg = new QgsExpressionSelectionDialog( mLayer );
@@ -838,22 +792,6 @@ void QgsAttributeTableDialog::on_mRemoveAttribute_clicked()
838792
}
839793
}
840794

841-
void QgsAttributeTableDialog::on_mFilterTableFields_clicked()
842-
{
843-
if ( !mLayer )
844-
{
845-
return;
846-
}
847-
848-
QgsOrganizeTableColumnsDialog dialog( mLayer, this );
849-
if ( dialog.exec() == QDialog::Accepted )
850-
{
851-
QgsAttributeTableConfig config = dialog.config();
852-
mLayer->setAttributeTableConfig( config );
853-
mMainView->setAttributeTableConfig( config );
854-
}
855-
}
856-
857795
void QgsAttributeTableDialog::filterQueryChanged( const QString& query )
858796
{
859797
QString str;

src/app/qgsattributetabledialog.h

-7
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
9191
* Reload the data
9292
*/
9393
void on_mReloadButton_clicked();
94-
/**
95-
* Filter the columns (open a dialog, ...)
96-
*/
97-
void on_mFilterTableFields_clicked();
98-
9994
/**
10095
* Inverts selection
10196
*/
@@ -156,8 +151,6 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
156151

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

159-
void on_mSortButton_clicked();
160-
161154
void on_mExpressionSelectButton_clicked();
162155
void filterColumnChanged( QObject* filterAction );
163156
void filterExpressionBuilder();

src/gui/attributetable/qgsdualview.cpp

+88
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
#include "qgsmessagelog.h"
2626
#include "qgsvectordataprovider.h"
2727
#include "qgsvectorlayercache.h"
28+
#include "qgsorganizetablecolumnsdialog.h"
2829

2930
#include <QClipboard>
3031
#include <QDialog>
3132
#include <QMenu>
3233
#include <QMessageBox>
3334
#include <QProgressDialog>
3435
#include <QSettings>
36+
#include <QGroupBox>
3537

3638
QgsDualView::QgsDualView( QWidget* parent )
3739
: QStackedWidget( parent )
@@ -40,6 +42,7 @@ QgsDualView::QgsDualView( QWidget* parent )
4042
, mFilterModel( nullptr )
4143
, mFeatureListModel( nullptr )
4244
, mAttributeForm( nullptr )
45+
, mHorizontalHeaderMenu( nullptr )
4346
, mLayerCache( nullptr )
4447
, mProgressDlg( nullptr )
4548
, mFeatureSelectionManager( nullptr )
@@ -67,6 +70,8 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
6770
mEditorContext = context;
6871

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

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

461+
void QgsDualView::showViewHeaderMenu( QPoint point )
462+
{
463+
delete mHorizontalHeaderMenu;
464+
mHorizontalHeaderMenu = new QMenu( this );
465+
QAction* organize = new QAction( tr( "&Organize columns..." ), mHorizontalHeaderMenu );
466+
connect( organize, SIGNAL( triggered( bool ) ), this, SLOT( organizeColumns() ) );
467+
mHorizontalHeaderMenu->addAction( organize );
468+
QAction* sort = new QAction( tr( "&Sort..." ), mHorizontalHeaderMenu );
469+
connect( sort, SIGNAL( triggered( bool ) ), this, SLOT( modifySort() ) );
470+
mHorizontalHeaderMenu->addAction( sort );
471+
mHorizontalHeaderMenu->popup( mTableView->horizontalHeader()->mapToGlobal( point ) );
472+
}
473+
474+
void QgsDualView::organizeColumns()
475+
{
476+
if ( !mLayerCache->layer() )
477+
{
478+
return;
479+
}
480+
481+
QgsOrganizeTableColumnsDialog dialog( mLayerCache->layer(), this );
482+
if ( dialog.exec() == QDialog::Accepted )
483+
{
484+
QgsAttributeTableConfig config = dialog.config();
485+
mLayerCache->layer()->setAttributeTableConfig( config );
486+
setAttributeTableConfig( config );
487+
}
488+
}
489+
490+
void QgsDualView::modifySort()
491+
{
492+
QgsVectorLayer* layer = mLayerCache->layer();
493+
if ( !layer )
494+
return;
495+
496+
QgsAttributeTableConfig config = layer->attributeTableConfig();
497+
498+
QDialog orderByDlg;
499+
orderByDlg.setWindowTitle( tr( "Configure attribute table sort order" ) );
500+
QDialogButtonBox* dialogButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
501+
QGridLayout* layout = new QGridLayout();
502+
connect( dialogButtonBox, SIGNAL( accepted() ), &orderByDlg, SLOT( accept() ) );
503+
connect( dialogButtonBox, SIGNAL( rejected() ), &orderByDlg, SLOT( reject() ) );
504+
orderByDlg.setLayout( layout );
505+
506+
QGroupBox* sortingGroupBox = new QGroupBox();
507+
sortingGroupBox->setTitle( tr( "Enable sorting order in attribute table" ) );
508+
sortingGroupBox->setCheckable( true );
509+
sortingGroupBox->setChecked( !sortExpression().isEmpty() );
510+
layout->addWidget( sortingGroupBox );
511+
sortingGroupBox->setLayout( new QGridLayout() );
512+
513+
QgsExpressionBuilderWidget* expressionBuilder = new QgsExpressionBuilderWidget();
514+
QgsExpressionContext context;
515+
context << QgsExpressionContextUtils::globalScope()
516+
<< QgsExpressionContextUtils::projectScope()
517+
<< QgsExpressionContextUtils::layerScope( layer );
518+
expressionBuilder->setExpressionContext( context );
519+
expressionBuilder->setLayer( layer );
520+
expressionBuilder->loadFieldNames();
521+
expressionBuilder->loadRecent( "generic" );
522+
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? layer->displayExpression() : sortExpression() );
523+
524+
sortingGroupBox->layout()->addWidget( expressionBuilder );
525+
526+
layout->addWidget( dialogButtonBox );
527+
if ( orderByDlg.exec() )
528+
{
529+
if ( sortingGroupBox->isChecked() )
530+
{
531+
setSortExpression( expressionBuilder->expressionText() );
532+
config.setSortExpression( expressionBuilder->expressionText() );
533+
}
534+
else
535+
{
536+
setSortExpression( QString() );
537+
config.setSortExpression( QString() );
538+
}
539+
540+
layer->setAttributeTableConfig( config );
541+
}
542+
}
543+
456544
void QgsDualView::zoomToCurrentFeature()
457545
{
458546
QModelIndex currentIndex = mTableView->currentIndex();

src/gui/attributetable/qgsdualview.h

+7
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
273273

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

276+
void showViewHeaderMenu( QPoint point );
277+
278+
void organizeColumns();
279+
280+
void modifySort();
281+
276282
void previewExpressionChanged( const QString& expression );
277283

278284
void sortByPreviewExpression();
@@ -312,6 +318,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
312318
QgsAttributeForm* mAttributeForm;
313319
QSignalMapper* mPreviewActionMapper;
314320
QMenu* mPreviewColumnsMenu;
321+
QMenu* mHorizontalHeaderMenu;
315322
QgsVectorLayerCache* mLayerCache;
316323
QProgressDialog* mProgressDlg;
317324
QgsIFeatureSelectionManager* mFeatureSelectionManager;

src/ui/qgsattributetabledialog.ui

-46
Original file line numberDiff line numberDiff line change
@@ -581,52 +581,6 @@
581581
</property>
582582
</widget>
583583
</item>
584-
<item>
585-
<widget class="QToolButton" name="mFilterTableFields">
586-
<property name="toolTip">
587-
<string>Organize table columns</string>
588-
</property>
589-
<property name="text">
590-
<string>...</string>
591-
</property>
592-
<property name="icon">
593-
<iconset resource="../../images/images.qrc">
594-
<normaloff>:/images/themes/default/mActionFilterTableFields.svg</normaloff>:/images/themes/default/mActionFilterTableFields.svg</iconset>
595-
</property>
596-
<property name="iconSize">
597-
<size>
598-
<width>18</width>
599-
<height>18</height>
600-
</size>
601-
</property>
602-
<property name="autoRaise">
603-
<bool>true</bool>
604-
</property>
605-
</widget>
606-
</item>
607-
<item>
608-
<widget class="QToolButton" name="mSortButton">
609-
<property name="toolTip">
610-
<string>Control the sort order</string>
611-
</property>
612-
<property name="text">
613-
<string>...</string>
614-
</property>
615-
<property name="icon">
616-
<iconset resource="../../images/images.qrc">
617-
<normaloff>:/images/themes/default/sort.svg</normaloff>:/images/themes/default/sort.svg</iconset>
618-
</property>
619-
<property name="iconSize">
620-
<size>
621-
<width>18</width>
622-
<height>18</height>
623-
</size>
624-
</property>
625-
<property name="autoRaise">
626-
<bool>true</bool>
627-
</property>
628-
</widget>
629-
</item>
630584
<item>
631585
<spacer name="horizontalSpacer">
632586
<property name="orientation">

0 commit comments

Comments
 (0)