Libkdepim

multiplyinglineeditor.h
1/*
2 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
3 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4
5 Refactored from earlier code by:
6 SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org>
7 SPDX-FileCopyrightText: 2004 Cornelius Schumacher <schumacher@kde.org>
8
9 SPDX-License-Identifier: LGPL-2.0-or-later
10*/
11
12#pragma once
13
14#include "kdepim_export.h"
15
16#include "multiplyingline.h"
17
18#include <KCompletion>
19#include <QObject>
20#include <QWidget>
21
22namespace KPIM
23{
24class MultiplyingLineView;
25
26/**
27 @short An Abstract Base Class used to create MultiplyingLines
28 Subclass this class and MultiplyingLine, then implement newLine() such that it allocates
29 and returns an instance of your MultiplyingLine.
30 */
31class KDEPIM_EXPORT MultiplyingLineFactory : public QObject
32{
33 Q_OBJECT
34public:
35 explicit MultiplyingLineFactory(QObject *parent)
36 : QObject(parent)
37 {
38 }
39
40 ~MultiplyingLineFactory() override = default;
41
42 virtual MultiplyingLine *newLine(QWidget *parent) = 0;
43 virtual int maximumRecipients()
44 {
45 return -1;
46 }
47};
48
49/**
50 @short An editor that adds rows (lines) of widgets and deletes them as the user edits
51
52 Line widgets in the MultiplyingLineEditor are usually composed of multiple
53 basic widgets. An example is below:
54
55 -------------------------------------------------
56 | ComboBox| Line edit | Checkbox | <-- 1 line
57 -------------------------------------------------
58 | ComboBox| Line edit | Checkbox | <-- another line
59
60 Default behavior is one line with default settings, and when
61 the user edits it, another line is automatically added.
62 Lines are added and deleted on demand.
63
64 Implement this class and MultiplyingLineData. Then implement
65 MultiplyingLineFactory to return instances of your line.
66*/
67class KDEPIM_EXPORT MultiplyingLineEditor : public QWidget
68{
69 Q_OBJECT
70
71public:
72 // We take ownership of factory
73 explicit MultiplyingLineEditor(MultiplyingLineFactory *factory, QWidget *parent = nullptr);
74
75 ~MultiplyingLineEditor() override;
76
77 /** Get the current line factory for this instance of the widget.
78 */
79 MultiplyingLineFactory *factory() const;
80
81 /** Retrieve the data from the editor */
82 [[nodiscard]] QList<MultiplyingLineData::Ptr> allData() const;
83
84 /** Retrieve the data of the active line */
85 MultiplyingLineData::Ptr activeData() const;
86
87 /** Clear all lines from the widget.
88 */
89 void clear();
90
91 /** Returns true if the user has made any modifications to the list of
92 recipients.
93 */
94 [[nodiscard]] bool isModified() const;
95
96 /** Resets the modified flag to false.
97 */
98 void clearModified();
99
100 /** Adds data to one line of the editor.
101 @param data The data you want to add.
102 Can be used to add an empty/default line.
103 */
104 bool addData(const MultiplyingLineData::Ptr &data = MultiplyingLineData::Ptr(), bool showDialogBox = true);
105
106 /** Removes data provided it can be found. The Data class must support operator==
107 @param data The data you want to add.
108 */
109 void removeData(const MultiplyingLineData::Ptr &data);
110
111 /**
112 Set the width of the left most column to be the argument width.
113 This method allows other widgets to align their label/combobox column with ours
114 by communicating how many pixels that first column is for them.
115 @param w what the left most column width should be
116 @return the width that is actually being used.
117 */
118 int setFirstColumnWidth(int w);
119
120 /**
121 Set completion mode for all lines
122 @param mode the completion mode
123 */
124 void setCompletionMode(KCompletion::CompletionMode mode);
125
126 [[nodiscard]] QList<MultiplyingLine *> lines() const;
127
128Q_SIGNALS:
129 void focusUp();
130 void focusDown();
131 void completionModeChanged(KCompletion::CompletionMode);
132 void sizeHintChanged();
133 void lineDeleted(int pos);
134 void lineAdded(KPIM::MultiplyingLine *);
135
136public Q_SLOTS:
137 void setFocus();
138 void setFocusTop();
139 void setFocusBottom();
140
141protected:
142 bool mModified = false;
143
144private:
145 MultiplyingLineFactory *const mMultiplyingLineFactory;
146 MultiplyingLineView *mView = nullptr;
147};
148}
An editor that adds rows (lines) of widgets and deletes them as the user edits.
An Abstract Base Class used to create MultiplyingLines Subclass this class and MultiplyingLine,...
Abstract Base Class representing a line in the Multiplying line widget.
Class KCheckComboBox::KCheckComboBoxPrivate.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.