QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
attributetable
qgsorganizetablecolumnsdialog.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsorganizetablecolumnsdialog.cpp
3
-------------------
4
date : Feb 2016
5
copyright : Stéphane Brunner
6
email : stephane.brunner@gmail.com
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
17
#include "
qgsorganizetablecolumnsdialog.h
"
18
19
#include "
qgsapplication.h
"
20
#include "
qgsattributetableview.h
"
21
#include "
qgseditorwidgetregistry.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
"
29
#include "
qgssearchquerybuilder.h
"
30
#include "
qgsvectorlayer.h
"
31
32
#include <QMessageBox>
33
#include <QString>
34
35
#include "moc_qgsorganizetablecolumnsdialog.cpp"
36
37
using namespace
Qt::StringLiterals;
38
39
QgsOrganizeTableColumnsDialog::QgsOrganizeTableColumnsDialog
(
const
QgsVectorLayer
*vl,
const
QgsAttributeTableConfig
&
config
, QWidget *parent, Qt::WindowFlags flags )
40
: QDialog( parent, flags )
41
{
42
setupUi(
this
);
43
QgsGui::enableAutoGeometryRestore
(
this
);
44
45
connect( mShowAllButton, &QAbstractButton::clicked,
this
, &
QgsOrganizeTableColumnsDialog::showAll
);
46
connect( mHideAllButton, &QAbstractButton::clicked,
this
, &
QgsOrganizeTableColumnsDialog::hideAll
);
47
connect( mToggleSelectionButton, &QAbstractButton::clicked,
this
, &
QgsOrganizeTableColumnsDialog::toggleSelection
);
48
49
if
( vl )
50
{
51
mConfig =
config
;
52
const
QgsFields
fields = vl->
fields
();
53
mConfig.update( fields );
54
55
mFieldsList->
clear
();
56
57
const
auto
constColumns = mConfig.columns();
58
for
(
const
QgsAttributeTableConfig::ColumnConfig
&columnConfig : constColumns )
59
{
60
QListWidgetItem *item =
nullptr
;
61
if
( columnConfig.type ==
QgsAttributeTableConfig::Action
)
62
{
63
item =
new
QListWidgetItem( tr(
"[Action Widget]"
), mFieldsList );
64
item->setIcon(
QgsApplication::getThemeIcon
( u
"/propertyicons/action.svg"
_s ) );
65
}
66
else
67
{
68
const
int
idx = fields.
lookupField
( columnConfig.name );
69
item =
new
QListWidgetItem( vl->
attributeDisplayName
( idx ), mFieldsList );
70
item->setIcon( fields.
iconForField
( idx,
true
) );
71
}
72
73
item->setCheckState( columnConfig.hidden ? Qt::Unchecked : Qt::Checked );
74
item->setData( Qt::UserRole, QVariant::fromValue( columnConfig ) );
75
}
76
}
77
78
if
( !vl || mConfig.columns().count() < 5 )
79
{
80
mShowAllButton->hide();
81
mHideAllButton->hide();
82
mToggleSelectionButton->hide();
83
}
84
}
85
87
QgsOrganizeTableColumnsDialog::QgsOrganizeTableColumnsDialog
(
const
QgsVectorLayer
*vl, QWidget *parent, Qt::WindowFlags flags )
88
:
QgsOrganizeTableColumnsDialog
( vl, vl->attributeTableConfig(), parent, flags )
89
{}
91
92
QgsAttributeTableConfig
QgsOrganizeTableColumnsDialog::config
()
const
93
{
94
QVector<QgsAttributeTableConfig::ColumnConfig> columns;
95
columns.reserve( mFieldsList->count() );
96
97
for
(
int
i = 0; i < mFieldsList->count(); i++ )
98
{
99
const
QListWidgetItem *item = mFieldsList->item( i );
100
QgsAttributeTableConfig::ColumnConfig
columnConfig = item->data( Qt::UserRole ).value<
QgsAttributeTableConfig::ColumnConfig
>();
101
102
columnConfig.
hidden
= item->checkState() == Qt::Unchecked;
103
104
columns.append( columnConfig );
105
}
106
107
QgsAttributeTableConfig
config
= mConfig;
108
config
.setColumns( columns );
109
return
config
;
110
}
111
112
void
QgsOrganizeTableColumnsDialog::showAll
()
113
{
114
for
(
int
i = 0; i < mFieldsList->count(); i++ )
115
{
116
mFieldsList->item( i )->setCheckState( Qt::Checked );
117
}
118
}
119
120
void
QgsOrganizeTableColumnsDialog::hideAll
()
121
{
122
for
(
int
i = 0; i < mFieldsList->count(); i++ )
123
{
124
mFieldsList->item( i )->setCheckState( Qt::Unchecked );
125
}
126
}
127
128
void
QgsOrganizeTableColumnsDialog::toggleSelection
()
129
{
130
for
( QListWidgetItem *item : mFieldsList->selectedItems() )
131
{
132
item->setCheckState( item->checkState() == Qt::Checked ? Qt::Unchecked : Qt::Checked );
133
}
134
}
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition
qgsapplication.cpp:904
QgsAttributeTableConfig
A container for configuration of the attribute table.
Definition
qgsattributetableconfig.h:36
QgsAttributeTableConfig::Action
@ Action
This column represents an action widget.
Definition
qgsattributetableconfig.h:46
QgsFields
Container of fields for a vector layer.
Definition
qgsfields.h:45
QgsFields::clear
void clear()
Removes all fields.
Definition
qgsfields.cpp:63
QgsFields::lookupField
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Definition
qgsfields.cpp:410
QgsFields::iconForField
QIcon iconForField(int fieldIdx, bool considerOrigin=false) const
Returns an icon corresponding to a field index, based on the field's type and source.
Definition
qgsfields.cpp:321
QgsGui::enableAutoGeometryRestore
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:225
QgsOrganizeTableColumnsDialog
Dialog for organising (hiding and reordering) columns in the attributes table.
Definition
qgsorganizetablecolumnsdialog.h:36
QgsOrganizeTableColumnsDialog::toggleSelection
void toggleSelection()
Toggle the check state of selected fields to hide or show them in the attribute table.
Definition
qgsorganizetablecolumnsdialog.cpp:128
QgsOrganizeTableColumnsDialog::showAll
void showAll()
showAll checks all the fields to show them all in the attribute table
Definition
qgsorganizetablecolumnsdialog.cpp:112
QgsOrganizeTableColumnsDialog::QgsOrganizeTableColumnsDialog
QgsOrganizeTableColumnsDialog(const QgsVectorLayer *vl, const QgsAttributeTableConfig &config, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::Window)
Constructor.
Definition
qgsorganizetablecolumnsdialog.cpp:39
QgsOrganizeTableColumnsDialog::hideAll
void hideAll()
hideAll unchecks all the fields to hide them all in the attribute table
Definition
qgsorganizetablecolumnsdialog.cpp:120
QgsOrganizeTableColumnsDialog::config
QgsAttributeTableConfig config() const
Gets the updated configuration.
Definition
qgsorganizetablecolumnsdialog.cpp:92
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
QgsVectorLayer::attributeDisplayName
Q_INVOKABLE QString attributeDisplayName(int index) const
Convenience function that returns the attribute alias if defined or the field name else.
Definition
qgsvectorlayer.cpp:3856
QgsVectorLayer::fields
QgsFields fields
Definition
qgsvectorlayer.h:422
qgsapplication.h
qgsattributetableview.h
qgseditorwidgetregistry.h
qgsexpression.h
qgsfields.h
qgsgui.h
qgsmapcanvas.h
qgsmessagebar.h
qgsorganizetablecolumnsdialog.h
qgsproject.h
qgsrubberband.h
qgssearchquerybuilder.h
qgsvectorlayer.h
QgsAttributeTableConfig::ColumnConfig
Defines the configuration of a column in the attribute table.
Definition
qgsattributetableconfig.h:53
QgsAttributeTableConfig::ColumnConfig::hidden
bool hidden
Flag that controls if the column is hidden.
Definition
qgsattributetableconfig.h:66
Generated on
for QGIS API Documentation by
1.17.0