QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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 "qgsaddtaborgroup.h"
20
21#include "qgshelp.h"
23#include "qgssettingstree.h"
24#include "qgsvectorlayer.h"
25
26#include <QComboBox>
27#include <QRadioButton>
28#include <QString>
29
30#include "moc_qgsaddtaborgroup.cpp"
31
32using namespace Qt::StringLiterals;
33
35 = new QgsSettingsEntryInteger( u"default-tab-column-count"_s, QgsSettingsTree::sTreeAttributeForm, 1, QObject::tr( "Default column count for tab containers in attribute forms" ) );
36
38 = new QgsSettingsEntryInteger( u"default-group-column-count"_s, QgsSettingsTree::sTreeAttributeForm, 1, QObject::tr( "Default column count for group box containers in attribute forms" ) );
39
40QgsAddAttributeFormContainerDialog::QgsAddAttributeFormContainerDialog( QgsVectorLayer *layer, const QList<ContainerPair> &existingContainerList, QModelIndex &currentItemIndex, QWidget *parent )
41 : QDialog( parent )
42 , mLayer( layer )
43 , mExistingContainers( existingContainerList )
44{
45 setupUi( this );
46
47 mTypeCombo->addItem( tr( "Tab" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) );
48 mTypeCombo->addItem( tr( "Group Box" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) );
49 mTypeCombo->addItem( tr( "Row" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Row ) );
50
51 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) ) );
52
53 mParentCombo->addItem( QString() );
54 if ( !mExistingContainers.isEmpty() )
55 {
56 int i = 0;
57 for ( const ContainerPair &container : std::as_const( mExistingContainers ) )
58 {
59 mParentCombo->addItem( container.first, i );
60 if ( currentItemIndex.isValid() && container.second == currentItemIndex )
61 {
62 mParentCombo->setCurrentIndex( i + 1 ); // Take empty item into account
63 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) ) );
64 }
65 ++i;
66 }
67 }
68
69 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAddAttributeFormContainerDialog::showHelp );
70
71 mColumnCountSpinBox->setValue( settingsDefaultTabColumnCount->value() );
72
73 setWindowTitle( tr( "Add Container for %1" ).arg( mLayer->name() ) );
74
75 connect( mTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsAddAttributeFormContainerDialog::containerTypeChanged );
76 containerTypeChanged();
77}
78
80{
81 return mName->text();
82}
83
85{
87 return QModelIndex();
88
89 if ( !mParentCombo->currentData().isValid() )
90 return QModelIndex();
91
92 const ContainerPair tab = mExistingContainers.at( mParentCombo->currentData().toInt() );
93 return tab.second;
94}
95
97{
98 return mColumnCountSpinBox->value();
99}
100
105
107{
108 if ( mColumnCountSpinBox->value() > 0 )
109 {
110 switch ( containerType() )
111 {
113 settingsDefaultGroupColumnCount->setValue( mColumnCountSpinBox->value() );
114 break;
116 settingsDefaultTabColumnCount->setValue( mColumnCountSpinBox->value() );
117 break;
119 break;
120 }
121 }
122
123 QDialog::accept();
124}
125
126void QgsAddAttributeFormContainerDialog::showHelp()
127{
128 QgsHelp::openHelp( u"working_with_vector/vector_properties.html#the-drag-and-drop-designer"_s );
129}
130
131void QgsAddAttributeFormContainerDialog::containerTypeChanged()
132{
133 const Qgis::AttributeEditorContainerType type = mTypeCombo->currentData().value<Qgis::AttributeEditorContainerType>();
134 switch ( type )
135 {
137 mParentCombo->show();
138 mLabelParent->show();
139 mColumnsLabel->show();
140 mColumnCountSpinBox->show();
141 mColumnCountSpinBox->setValue( settingsDefaultGroupColumnCount->value() );
142 break;
144 mParentCombo->hide();
145 mLabelParent->hide();
146 mColumnsLabel->show();
147 mColumnCountSpinBox->show();
148 mColumnCountSpinBox->setValue( settingsDefaultTabColumnCount->value() );
149 break;
151 mParentCombo->show();
152 mLabelParent->show();
153 mColumnsLabel->hide();
154 mColumnCountSpinBox->hide();
155 break;
156 }
157}
AttributeEditorContainerType
Attribute editor container types.
Definition qgis.h:5925
@ Row
A row of editors (horizontal layout).
Definition qgis.h:5928
QPair< QString, QModelIndex > ContainerPair
QModelIndex parentContainerItem() const
Returns tree model index corresponding to the selected parent container.
QgsAddAttributeFormContainerDialog(QgsVectorLayer *layer, const QList< ContainerPair > &existingContainerList, QModelIndex &currentItemIndex, QWidget *parent=nullptr)
constructor
Qgis::AttributeEditorContainerType containerType() const
Returns the container type.
QString name()
Returns the name of the container.
void accept() override
Accepts the dialog.
static const QgsSettingsEntryInteger * settingsDefaultGroupColumnCount
Settings entry for the default column count for group box containers.
static const QgsSettingsEntryInteger * settingsDefaultTabColumnCount
Settings entry for the default column count for tab containers.
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:41
An integer settings entry.
static QgsSettingsTreeNode * sTreeAttributeForm
Represents a vector layer which manages a vector based dataset.