Messagelib

aggregationeditor.cpp
1 /******************************************************************************
2  *
3  * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <[email protected]>
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  *
7  *******************************************************************************/
8 
9 #include "utils/aggregationeditor.h"
10 #include "core/aggregation.h"
11 #include "utils/comboboxutils.h"
12 
13 #include <KTextEdit>
14 #include <QCheckBox>
15 #include <QGridLayout>
16 #include <QLabel>
17 #include <QLineEdit>
18 #include <QPushButton>
19 
20 #include <KLocalizedString>
21 #include <QComboBox>
22 
23 using namespace MessageList::Utils;
24 using namespace MessageList::Core;
25 
26 AggregationEditor::AggregationEditor(QWidget *parent)
27  : OptionSetEditor(parent)
28 {
29  // Grouping and Threading tab
30  auto tab = new QWidget(this);
31  addTab(tab, i18n("Groups && Threading"));
32 
33  auto tabg = new QGridLayout(tab);
34 
35  tabg->addWidget(new QLabel(i18n("Grouping:"), tab), 0, 0);
36  mGroupingCombo = new QComboBox(tab);
37  tabg->addWidget(mGroupingCombo, 0, 1);
38 
39  connect(mGroupingCombo, qOverload<int>(&QComboBox::activated), this, &AggregationEditor::groupingComboActivated);
40 
41  tabg->addWidget(new QLabel(i18n("Group expand policy:"), tab), 3, 0);
42  mGroupExpandPolicyCombo = new QComboBox(tab);
43  tabg->addWidget(mGroupExpandPolicyCombo, 3, 1);
44 
45  tabg->addWidget(new QLabel(i18n("Threading:"), tab), 4, 0);
46  mThreadingCombo = new QComboBox(tab);
47  tabg->addWidget(mThreadingCombo, 4, 1);
48 
49  connect(mThreadingCombo, qOverload<int>(&QComboBox::activated), this, &AggregationEditor::threadingComboActivated);
50 
51  tabg->addWidget(new QLabel(i18n("Thread leader:"), tab), 5, 0);
52  mThreadLeaderCombo = new QComboBox(tab);
53  tabg->addWidget(mThreadLeaderCombo, 5, 1);
54 
55  tabg->addWidget(new QLabel(i18n("Thread expand policy:"), tab), 6, 0);
56  mThreadExpandPolicyCombo = new QComboBox(tab);
57  tabg->addWidget(mThreadExpandPolicyCombo, 6, 1);
58 
59  tabg->setColumnStretch(1, 1);
60  tabg->setRowStretch(9, 1);
61 
62  // Advanced tab
63  tab = new QWidget(this);
64  addTab(tab, i18nc("@title:tab Advanced settings tab for aggregation mode", "Advanced"));
65 
66  tabg = new QGridLayout(tab);
67 
68  tabg->addWidget(new QLabel(i18n("Fill view strategy:"), tab), 0, 0);
69  mFillViewStrategyCombo = new QComboBox(tab);
70  tabg->addWidget(mFillViewStrategyCombo, 0, 1);
71 
72  tabg->setColumnStretch(1, 1);
73  tabg->setRowStretch(1, 1);
74  fillGroupingCombo();
75  fillThreadingCombo();
76  fillFillViewStrategyCombo();
77 
78  fillThreadLeaderCombo();
79  fillThreadExpandPolicyCombo();
80  fillGroupExpandPolicyCombo();
81 }
82 
83 AggregationEditor::~AggregationEditor() = default;
84 
86 {
87  mCurrentAggregation = set;
88 
89  if (!mCurrentAggregation) {
90  setEnabled(false);
91  return;
92  }
93  setEnabled(true);
94  nameEdit()->setText(set->name());
95  descriptionEdit()->setText(set->description());
96 
97  ComboBoxUtils::setIntegerOptionComboValue(mGroupingCombo, (int)mCurrentAggregation->grouping());
98  ComboBoxUtils::setIntegerOptionComboValue(mThreadingCombo, (int)mCurrentAggregation->threading());
99  ComboBoxUtils::setIntegerOptionComboValue(mFillViewStrategyCombo, (int)mCurrentAggregation->fillViewStrategy());
100 
101  // Necessary to fill after apply mGroupingCombo/mThreadingCombo/mFillViewStrategyCombo otherwise other combo are not filled.
102  fillThreadLeaderCombo();
103  fillThreadExpandPolicyCombo();
104  fillGroupExpandPolicyCombo();
105 
106  ComboBoxUtils::setIntegerOptionComboValue(mThreadLeaderCombo, (int)mCurrentAggregation->threadLeader());
107 
108  ComboBoxUtils::setIntegerOptionComboValue(mThreadExpandPolicyCombo, (int)mCurrentAggregation->threadExpandPolicy());
109 
110  ComboBoxUtils::setIntegerOptionComboValue(mGroupExpandPolicyCombo, (int)mCurrentAggregation->groupExpandPolicy());
111  fillThreadLeaderCombo();
112  fillThreadExpandPolicyCombo();
113  fillGroupExpandPolicyCombo();
114 
115  setReadOnly(mCurrentAggregation->readOnly());
116 }
117 
118 void AggregationEditor::setReadOnly(bool readOnly)
119 {
120  mGroupingCombo->setEnabled(!readOnly);
121  mGroupExpandPolicyCombo->setEnabled(!readOnly);
122  mThreadingCombo->setEnabled(!readOnly);
123  mThreadLeaderCombo->setEnabled(!readOnly);
124  mThreadExpandPolicyCombo->setEnabled(!readOnly);
125  mFillViewStrategyCombo->setEnabled(!readOnly);
126 
127  OptionSetEditor::setReadOnly(readOnly);
128 }
129 
131 {
132  mCurrentAggregation->setName(nameEdit()->text());
133  mCurrentAggregation->setDescription(descriptionEdit()->toPlainText());
134 
135  mCurrentAggregation->setGrouping(static_cast<Aggregation::Grouping>(ComboBoxUtils::getIntegerOptionComboValue(mGroupingCombo, 0)));
136 
137  mCurrentAggregation->setGroupExpandPolicy(
138  static_cast<Aggregation::GroupExpandPolicy>(ComboBoxUtils::getIntegerOptionComboValue(mGroupExpandPolicyCombo, 0)));
139 
140  mCurrentAggregation->setThreading(static_cast<Aggregation::Threading>(ComboBoxUtils::getIntegerOptionComboValue(mThreadingCombo, 0)));
141 
142  mCurrentAggregation->setThreadLeader(static_cast<Aggregation::ThreadLeader>(ComboBoxUtils::getIntegerOptionComboValue(mThreadLeaderCombo, 0)));
143 
144  mCurrentAggregation->setThreadExpandPolicy(
145  static_cast<Aggregation::ThreadExpandPolicy>(ComboBoxUtils::getIntegerOptionComboValue(mThreadExpandPolicyCombo, 0)));
146 
147  mCurrentAggregation->setFillViewStrategy(static_cast<Aggregation::FillViewStrategy>(ComboBoxUtils::getIntegerOptionComboValue(mFillViewStrategyCombo, 0)));
148 }
149 
150 void AggregationEditor::slotNameEditTextEdited(const QString &newName)
151 {
152  if (!mCurrentAggregation) {
153  return;
154  }
155  mCurrentAggregation->setName(newName);
156  Q_EMIT aggregationNameChanged();
157 }
158 
159 void AggregationEditor::fillGroupingCombo()
160 {
161  ComboBoxUtils::fillIntegerOptionCombo(mGroupingCombo, Aggregation::enumerateGroupingOptions());
162 }
163 
164 void AggregationEditor::groupingComboActivated(int)
165 {
166  fillGroupExpandPolicyCombo();
167  fillThreadLeaderCombo();
168 }
169 
170 void AggregationEditor::fillGroupExpandPolicyCombo()
171 {
172  ComboBoxUtils::fillIntegerOptionCombo(mGroupExpandPolicyCombo,
173  Aggregation::enumerateGroupExpandPolicyOptions(
174  (Aggregation::Grouping)ComboBoxUtils::getIntegerOptionComboValue(mGroupingCombo, Aggregation::NoGrouping)));
175 }
176 
177 void AggregationEditor::fillThreadingCombo()
178 {
179  ComboBoxUtils::fillIntegerOptionCombo(mThreadingCombo, Aggregation::enumerateThreadingOptions());
180 }
181 
182 void AggregationEditor::threadingComboActivated(int)
183 {
184  fillThreadLeaderCombo();
185  fillThreadExpandPolicyCombo();
186 }
187 
188 void AggregationEditor::fillThreadLeaderCombo()
189 {
190  ComboBoxUtils::fillIntegerOptionCombo(mThreadLeaderCombo,
191  Aggregation::enumerateThreadLeaderOptions(
192  (Aggregation::Grouping)ComboBoxUtils::getIntegerOptionComboValue(mGroupingCombo, Aggregation::NoGrouping),
193  (Aggregation::Threading)ComboBoxUtils::getIntegerOptionComboValue(mThreadingCombo, Aggregation::NoThreading)));
194 }
195 
196 void AggregationEditor::fillThreadExpandPolicyCombo()
197 {
198  ComboBoxUtils::fillIntegerOptionCombo(mThreadExpandPolicyCombo,
199  Aggregation::enumerateThreadExpandPolicyOptions(
200  (Aggregation::Threading)ComboBoxUtils::getIntegerOptionComboValue(mThreadingCombo, Aggregation::NoThreading)));
201 }
202 
203 void AggregationEditor::fillFillViewStrategyCombo()
204 {
205  ComboBoxUtils::fillIntegerOptionCombo(mFillViewStrategyCombo, Aggregation::enumerateFillViewStrategyOptions());
206 }
A set of aggregation options that can be applied to the MessageList::Model in a single shot...
Definition: aggregation.h:28
Threading
The available threading methods.
Definition: aggregation.h:65
void setIntegerOptionComboValue(QComboBox *combo, int value)
Sets the currently selected option in the specified combo.
The implementation independent part of the MessageList library.
Definition: aggregation.h:21
void setEnabled(bool)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void activated(int index)
The base class for the OptionSet editors.
void commit()
Explicitly commits the changes in the editor to the edited Aggregation, if any.
int getIntegerOptionComboValue(QComboBox *combo, int defaultValue)
Returns the identifier of the currently selected option in the specified combo.
QString i18n(const char *text, const TYPE &arg...)
Grouping
Message grouping.
Definition: aggregation.h:36
void fillIntegerOptionCombo(QComboBox *combo, const QVector< QPair< QString, int >> &optionDescriptors)
Fills the specified QComboBox with the options available in optionDescriptors.
QWidget(QWidget *parent, Qt::WindowFlags f)
QString text() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void editAggregation(Core::Aggregation *set)
Sets the Aggregation to be edited.
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 23:16:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.