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());
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);
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 }
const QString & description() const
Returns a description of this option set.
Definition: optionset.h:79
void setDescription(const QString &description)
Sets the description for this option set.
Definition: optionset.h:87
QWidget(QWidget *parent, Qt::WindowFlags f)
void fillIntegerOptionCombo(QComboBox *combo, const QVector< QPair< QString, int >> &optionDescriptors)
Fills the specified QComboBox with the options available in optionDescriptors.
Q_EMITQ_EMIT
void setName(const QString &name)
Sets the name of this OptionSet.
Definition: optionset.h:69
QLineEdit * nameEdit() const
Returns the editor for the name of the OptionSet.
void setGrouping(Grouping g)
Sets the Grouping option.
Definition: aggregation.h:145
void setIntegerOptionComboValue(QComboBox *combo, int value)
Sets the currently selected option in the specified combo.
GroupExpandPolicy groupExpandPolicy() const
Returns the current GroupExpandPolicy.
Definition: aggregation.h:160
void aggregationNameChanged()
This is triggered when the aggregation name changes in the editor text field.
const QString & name() const
Returns the name of this OptionSet.
Definition: optionset.h:59
void setThreading(Threading t)
Sets the threading method option.
Definition: aggregation.h:193
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
ThreadExpandPolicy threadExpandPolicy() const
Returns the current thread expand policy.
Definition: aggregation.h:235
Grouping grouping() const
Returns the currently set Grouping option.
Definition: aggregation.cpp:38
void commit()
Explicitly commits the changes in the editor to the edited Aggregation, if any.
QString i18n(const char *text, const TYPE &arg...)
void setText(const QString &)
void setGroupExpandPolicy(GroupExpandPolicy groupExpandPolicy)
Sets the GroupExpandPolicy for the groups.
Definition: aggregation.h:169
ThreadExpandPolicy
The available thread expand policies.
Definition: aggregation.h:90
void setText(const QString &text)
void setEnabled(bool)
void setFillViewStrategy(FillViewStrategy fillViewStrategy)
Sets the current fill view strategy.
Definition: aggregation.h:269
void editAggregation(Core::Aggregation *set)
Sets the Aggregation to be edited.
FillViewStrategy
The available fill view strategies.
Definition: aggregation.h:104
Threading
The available threading methods.
Definition: aggregation.h:65
KTextEdit * descriptionEdit() const
Returns the editor for the description of the OptionSet.
FillViewStrategy fillViewStrategy() const
Returns the current fill view strategy.
Definition: aggregation.h:261
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setThreadExpandPolicy(ThreadExpandPolicy threadExpandPolicy)
Sets the current thread expand policy.
Definition: aggregation.h:245
GroupExpandPolicy
The available group expand policies.
Definition: aggregation.h:53
The base class for the OptionSet editors.
ThreadLeader threadLeader() const
Returns the current thread leader determination method.
Definition: aggregation.h:208
ThreadLeader
The available thread leading options.
Definition: aggregation.h:78
void setThreadLeader(ThreadLeader tl)
Sets the current thread leader determination method.
Definition: aggregation.h:218
void activated(int index)
Threading threading() const
Returns the current threading method.
Definition: aggregation.h:185
A set of aggregation options that can be applied to the MessageList::Model in a single shot.
Definition: aggregation.h:28
int getIntegerOptionComboValue(QComboBox *combo, int defaultValue)
Returns the identifier of the currently selected option in the specified combo.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed May 25 2022 03:55:39 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.