QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsorganizetablecolumnsdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsorganizetablecolumnsdialog.cpp
3 -------------------
4 date : Feb 2016
5 copyright : Stéphane Brunner
7
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18
19#include "qgsapplication.h"
22#include "qgsexpression.h"
23#include "qgsfields.h"
24#include "qgsgui.h"
25#include "qgsmapcanvas.h"
26#include "qgsmessagebar.h"
27#include "qgsproject.h"
28#include "qgsrubberband.h"
30#include "qgsvectorlayer.h"
31
32#include <QMessageBox>
33
34#include "moc_qgsorganizetablecolumnsdialog.cpp"
35
37 : QDialog( parent, flags )
38{
39 setupUi( this );
41
42 connect( mShowAllButton, &QAbstractButton::clicked, this, &QgsOrganizeTableColumnsDialog::showAll );
43 connect( mHideAllButton, &QAbstractButton::clicked, this, &QgsOrganizeTableColumnsDialog::hideAll );
44 connect( mToggleSelectionButton, &QAbstractButton::clicked, this, &QgsOrganizeTableColumnsDialog::toggleSelection );
45
46 if ( vl )
47 {
48 mConfig = config;
49 const QgsFields fields = vl->fields();
50 mConfig.update( fields );
51
52 mFieldsList->clear();
53
54 const auto constColumns = mConfig.columns();
55 for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : constColumns )
56 {
57 QListWidgetItem *item = nullptr;
58 if ( columnConfig.type == QgsAttributeTableConfig::Action )
59 {
60 item = new QListWidgetItem( tr( "[Action Widget]" ), mFieldsList );
61 item->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/action.svg" ) ) );
62 }
63 else
64 {
65 const int idx = fields.lookupField( columnConfig.name );
66 item = new QListWidgetItem( vl->attributeDisplayName( idx ), mFieldsList );
67 item->setIcon( fields.iconForField( idx, true ) );
68 }
69
70 item->setCheckState( columnConfig.hidden ? Qt::Unchecked : Qt::Checked );
71 item->setData( Qt::UserRole, QVariant::fromValue( columnConfig ) );
72 }
73 }
74
75 if ( !vl || mConfig.columns().count() < 5 )
76 {
77 mShowAllButton->hide();
78 mHideAllButton->hide();
79 mToggleSelectionButton->hide();
80 }
81}
82
84QgsOrganizeTableColumnsDialog::QgsOrganizeTableColumnsDialog( const QgsVectorLayer *vl, QWidget *parent, Qt::WindowFlags flags )
85 : QgsOrganizeTableColumnsDialog( vl, vl->attributeTableConfig(), parent, flags )
86{
87}
89
91{
92 QVector<QgsAttributeTableConfig::ColumnConfig> columns;
93 columns.reserve( mFieldsList->count() );
94
95 for ( int i = 0; i < mFieldsList->count(); i++ )
96 {
97 const QListWidgetItem *item = mFieldsList->item( i );
98 QgsAttributeTableConfig::ColumnConfig columnConfig = item->data( Qt::UserRole ).value<QgsAttributeTableConfig::ColumnConfig>();
99
100 columnConfig.hidden = item->checkState() == Qt::Unchecked;
101
102 columns.append( columnConfig );
103 }
104
106 config.setColumns( columns );
107 return config;
108}
109
111{
112 for ( int i = 0; i < mFieldsList->count(); i++ )
113 {
114 mFieldsList->item( i )->setCheckState( Qt::Checked );
115 }
116}
117
119{
120 for ( int i = 0; i < mFieldsList->count(); i++ )
121 {
122 mFieldsList->item( i )->setCheckState( Qt::Unchecked );
123 }
124}
125
127{
128 for ( QListWidgetItem *item : mFieldsList->selectedItems() )
129 {
130 item->setCheckState( item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked );
131 }
132}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
A container for configuration of the attribute table.
@ Action
This column represents an action widget.
Container of fields for a vector layer.
Definition qgsfields.h:46
void clear()
Removes all fields.
Definition qgsfields.cpp:61
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QIcon iconForField(int fieldIdx, bool considerOrigin=false) const
Returns an icon corresponding to a field index, based on the field's type and source.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:221
Dialog for organising (hiding and reordering) columns in the attributes table.
void toggleSelection()
Toggle the check state of selected fields to hide or show them in the attribute table.
void showAll()
showAll checks all the fields to show them all in the attribute table
QgsOrganizeTableColumnsDialog(const QgsVectorLayer *vl, const QgsAttributeTableConfig &config, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::Window)
Constructor.
void hideAll()
hideAll unchecks all the fields to hide them all in the attribute table
QgsAttributeTableConfig config() const
Gets the updated configuration.
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else.
Defines the configuration of a column in the attribute table.
bool hidden
Flag that controls if the column is hidden.