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 <QLineEdit>
14 #include <KTextEdit>
15 #include <QLabel>
16 #include <QGridLayout>
17 #include <QPushButton>
18 #include <QCheckBox>
19 
20 #include <QComboBox>
21 #include <KLocalizedString>
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()
84 {
85 }
86 
88 {
89  mCurrentAggregation = set;
90 
91  if (!mCurrentAggregation) {
92  setEnabled(false);
93  return;
94  }
95  setEnabled(true);
96  nameEdit()->setText(set->name());
97  descriptionEdit()->setText(set->description());
98 
99  ComboBoxUtils::setIntegerOptionComboValue(mGroupingCombo, (int)mCurrentAggregation->grouping());
101  (int)mCurrentAggregation->threading());
102  ComboBoxUtils::setIntegerOptionComboValue(mFillViewStrategyCombo,
103  (int)mCurrentAggregation->fillViewStrategy());
104 
105  //Necessary to fill after apply mGroupingCombo/mThreadingCombo/mFillViewStrategyCombo otherwise other combo are not filled.
106  fillThreadLeaderCombo();
107  fillThreadExpandPolicyCombo();
108  fillGroupExpandPolicyCombo();
109 
111  (int)mCurrentAggregation->threadLeader());
112 
113  ComboBoxUtils::setIntegerOptionComboValue(mThreadExpandPolicyCombo,
114  (int)mCurrentAggregation->threadExpandPolicy());
115 
116  ComboBoxUtils::setIntegerOptionComboValue(mGroupExpandPolicyCombo,
117  (int)mCurrentAggregation->groupExpandPolicy());
118  fillThreadLeaderCombo();
119  fillThreadExpandPolicyCombo();
120  fillGroupExpandPolicyCombo();
121 
122  setReadOnly(mCurrentAggregation->readOnly());
123 }
124 
125 void AggregationEditor::setReadOnly(bool readOnly)
126 {
127  mGroupingCombo->setEnabled(!readOnly);
128  mGroupExpandPolicyCombo->setEnabled(!readOnly);
129  mThreadingCombo->setEnabled(!readOnly);
130  mThreadLeaderCombo->setEnabled(!readOnly);
131  mThreadExpandPolicyCombo->setEnabled(!readOnly);
132  mFillViewStrategyCombo->setEnabled(!readOnly);
133 
134  OptionSetEditor::setReadOnly(readOnly);
135 }
136 
138 {
139  mCurrentAggregation->setName(nameEdit()->text());
140  mCurrentAggregation->setDescription(descriptionEdit()->toPlainText());
141 
142  mCurrentAggregation->setGrouping(
143  static_cast<Aggregation::Grouping>(ComboBoxUtils::getIntegerOptionComboValue(mGroupingCombo, 0))
144  );
145 
146  mCurrentAggregation->setGroupExpandPolicy(
147  static_cast<Aggregation::GroupExpandPolicy>(ComboBoxUtils::getIntegerOptionComboValue(mGroupExpandPolicyCombo, 0))
148  );
149 
150  mCurrentAggregation->setThreading(
151  static_cast<Aggregation::Threading>(ComboBoxUtils::getIntegerOptionComboValue(mThreadingCombo, 0))
152  );
153 
154  mCurrentAggregation->setThreadLeader(
155  static_cast<Aggregation::ThreadLeader>(ComboBoxUtils::getIntegerOptionComboValue(mThreadLeaderCombo, 0))
156  );
157 
158  mCurrentAggregation->setThreadExpandPolicy(
159  static_cast<Aggregation::ThreadExpandPolicy>(ComboBoxUtils::getIntegerOptionComboValue(mThreadExpandPolicyCombo, 0))
160  );
161 
162  mCurrentAggregation->setFillViewStrategy(
163  static_cast<Aggregation::FillViewStrategy>(ComboBoxUtils::getIntegerOptionComboValue(mFillViewStrategyCombo, 0))
164  );
165 }
166 
167 void AggregationEditor::slotNameEditTextEdited(const QString &newName)
168 {
169  if (!mCurrentAggregation) {
170  return;
171  }
172  mCurrentAggregation->setName(newName);
173  Q_EMIT aggregationNameChanged();
174 }
175 
176 void AggregationEditor::fillGroupingCombo()
177 {
179  mGroupingCombo,
180  Aggregation::enumerateGroupingOptions()
181  );
182 }
183 
184 void AggregationEditor::groupingComboActivated(int)
185 {
186  fillGroupExpandPolicyCombo();
187  fillThreadLeaderCombo();
188 }
189 
190 void AggregationEditor::fillGroupExpandPolicyCombo()
191 {
193  mGroupExpandPolicyCombo,
194  Aggregation::enumerateGroupExpandPolicyOptions(
195  (Aggregation::Grouping)ComboBoxUtils::getIntegerOptionComboValue(mGroupingCombo, Aggregation::NoGrouping)
196  )
197  );
198 }
199 
200 void AggregationEditor::fillThreadingCombo()
201 {
203  mThreadingCombo,
204  Aggregation::enumerateThreadingOptions()
205  );
206 }
207 
208 void AggregationEditor::threadingComboActivated(int)
209 {
210  fillThreadLeaderCombo();
211  fillThreadExpandPolicyCombo();
212 }
213 
214 void AggregationEditor::fillThreadLeaderCombo()
215 {
217  mThreadLeaderCombo,
218  Aggregation::enumerateThreadLeaderOptions(
219  (Aggregation::Grouping)ComboBoxUtils::getIntegerOptionComboValue(mGroupingCombo, Aggregation::NoGrouping),
220  (Aggregation::Threading)ComboBoxUtils::getIntegerOptionComboValue(mThreadingCombo, Aggregation::NoThreading)
221  )
222  );
223 }
224 
225 void AggregationEditor::fillThreadExpandPolicyCombo()
226 {
228  mThreadExpandPolicyCombo,
229  Aggregation::enumerateThreadExpandPolicyOptions(
230  (Aggregation::Threading)ComboBoxUtils::getIntegerOptionComboValue(mThreadingCombo, Aggregation::NoThreading)
231  )
232  );
233 }
234 
235 void AggregationEditor::fillFillViewStrategyCombo()
236 {
238  mFillViewStrategyCombo,
239  Aggregation::enumerateFillViewStrategyOptions()
240  );
241 }
A set of aggregation options that can be applied to the MessageList::Model in a single shot...
Definition: aggregation.h:27
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 fillIntegerOptionCombo(QComboBox *combo, const QVector< QPair< QString, int > > &optionDescriptors)
Fills the specified QComboBox with the options available in optionDescriptors.
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
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 Tue Jan 26 2021 23:14:05 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.