QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsaddtaborgroup.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsaddtaborgroup.h
3 Add a tab or a group for the tab and group display of fields
4 -------------------
5 begin : 2012-07-30
6 copyright : (C) 2012 by Denis Rouzaud
7 email : denis dot rouzaud at gmail dot com
8***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#include "qgsvectorlayer.h"
20#include "qgsaddtaborgroup.h"
21#include "moc_qgsaddtaborgroup.cpp"
22#include "qgssettings.h"
23#include "qgshelp.h"
24
25#include <QTreeWidgetItem>
26#include <QComboBox>
27#include <QRadioButton>
28
29QgsAddAttributeFormContainerDialog::QgsAddAttributeFormContainerDialog( QgsVectorLayer *lyr, const QList<ContainerPair> &existingContainerList, QTreeWidgetItem *currentTab, QWidget *parent )
30 : QDialog( parent )
31 , mLayer( lyr )
32 , mExistingContainers( existingContainerList )
33{
34 setupUi( this );
35
36 mTypeCombo->addItem( tr( "Tab" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) );
37 mTypeCombo->addItem( tr( "Group Box" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) );
38 mTypeCombo->addItem( tr( "Row" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Row ) );
39
40 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) ) );
41
42 mParentCombo->addItem( QString() );
43 if ( !mExistingContainers.isEmpty() )
44 {
45 int i = 0;
46 for ( const ContainerPair &container : std::as_const( mExistingContainers ) )
47 {
48 mParentCombo->addItem( container.first, i );
49 if ( container.second == currentTab )
50 {
51 mParentCombo->setCurrentIndex( i );
52 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) ) );
53 }
54 ++i;
55 }
56 }
57
58 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAddAttributeFormContainerDialog::showHelp );
59
60 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), 1 ).toInt() );
61
62 setWindowTitle( tr( "Add Container for %1" ).arg( mLayer->name() ) );
63
64 connect( mTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsAddAttributeFormContainerDialog::containerTypeChanged );
65 containerTypeChanged();
66}
67
69{
70 return mName->text();
71}
72
74{
76 return nullptr;
77
78 if ( !mParentCombo->currentData().isValid() )
79 return nullptr;
80
81 const ContainerPair tab = mExistingContainers.at( mParentCombo->currentData().toInt() );
82 return tab.second;
83}
84
86{
87 return mColumnCountSpinBox->value();
88}
89
94
96{
97 if ( mColumnCountSpinBox->value() > 0 )
98 {
99 switch ( containerType() )
100 {
102 QgsSettings().setValue( QStringLiteral( "/qgis/attributeForm/defaultGroupColumnCount" ), mColumnCountSpinBox->value() );
103 break;
105 QgsSettings().setValue( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), mColumnCountSpinBox->value() );
106 break;
108 break;
109 }
110 }
111
112 QDialog::accept();
113}
114
115void QgsAddAttributeFormContainerDialog::showHelp()
116{
117 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#the-drag-and-drop-designer" ) );
118}
119
120void QgsAddAttributeFormContainerDialog::containerTypeChanged()
121{
122 const Qgis::AttributeEditorContainerType type = mTypeCombo->currentData().value<Qgis::AttributeEditorContainerType>();
123 switch ( type )
124 {
126 mParentCombo->show();
127 mLabelParent->show();
128 mColumnsLabel->show();
129 mColumnCountSpinBox->show();
130 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultGroupColumnCount" ), 1 ).toInt() );
131 break;
133 mParentCombo->hide();
134 mLabelParent->hide();
135 mColumnsLabel->show();
136 mColumnCountSpinBox->show();
137 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), 1 ).toInt() );
138 break;
140 mParentCombo->show();
141 mLabelParent->show();
142 mColumnsLabel->hide();
143 mColumnCountSpinBox->hide();
144 break;
145 }
146}
AttributeEditorContainerType
Attribute editor container types.
Definition qgis.h:5144
@ Row
A row of editors (horizontal layout)
QPair< QString, QTreeWidgetItem * > ContainerPair
Qgis::AttributeEditorContainerType containerType() const
Returns the container type.
QString name()
Returns the name of the tab or group.
void accept() override
Accepts the dialog.
QgsAddAttributeFormContainerDialog(QgsVectorLayer *lyr, const QList< ContainerPair > &existingContainerList, QTreeWidgetItem *currentTab=nullptr, QWidget *parent=nullptr)
constructor
QTreeWidgetItem * parentContainerItem()
Returns tree item corresponding to the selected parent container.
int columnCount() const
Returns the column count.
QList< ContainerPair > mExistingContainers
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
QString name
Definition qgsmaplayer.h:80
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Represents a vector layer which manages a vector based data sets.