1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2010-06-12
* Description : Special line edit for adding or creating tags
*
* SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
* SPDX-FileCopyrightText: 1997 by Sven Radej <sven dot radej at iname dot com>
* SPDX-FileCopyrightText: 1999 by Patrick Ward <PAT_WARD at HP-USA-om5 dot om dot hp dot com>
* SPDX-FileCopyrightText: 1999 by Preston Brown <pbrown at kde dot org>
* SPDX-FileCopyrightText: 2000-2001 by Dawit Alemayehu <adawit at kde dot org>
* SPDX-FileCopyrightText: 2000-2001 by Carsten Pfeiffer <pfeiffer at kde dot org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "addtagslineedit.h"
// Local includes
#include "digikam_debug.h"
#include "tagscompleter.h"
#include "album.h"
#include "albummodel.h"
#include "albumfiltermodel.h"
#include "tagtreeview.h"
#include "taggingactionfactory.h"
namespace Digikam
{
class Q_DECL_HIDDEN AddTagsLineEdit::Private
{
public:
Private() = default;
TagCompleter* completer = nullptr;
TagTreeView* tagView = nullptr;
AlbumFilterModel* tagFilterModel = nullptr;
TaggingAction currentTaggingAction;
int parentTagId = 0;
bool returnPressed = false;
};
AddTagsLineEdit::AddTagsLineEdit(QWidget* const parent)
: QLineEdit(parent),
d (new Private)
{
setClearButtonEnabled(true);
d->completer = new TagCompleter(this);
d->completer->setMaxVisibleItems(15);
setCompleter(d->completer);
connect(this, SIGNAL(returnPressed()),
this, SLOT(slotReturnPressed()));
connect(this, SIGNAL(editingFinished()),
this, SLOT(slotEditingFinished()));
connect(this, SIGNAL(textEdited(QString)),
this, SLOT(slotTextEdited(QString)));
connect(d->completer, QOverload<const TaggingAction&>::of(&TagCompleter::signalActivated),
d->completer, [this](const TaggingAction& action)
{
completerActivated(action);
}
);
connect(d->completer, QOverload<const TaggingAction&>::of(&TagCompleter::signalHighlighted),
d->completer, [this](const TaggingAction& action)
{
completerHighlighted(action);
}
);
}
AddTagsLineEdit::~AddTagsLineEdit()
{
delete d;
}
void AddTagsLineEdit::setSupportingTagModel(TagModel* const model)
{
d->completer->setSupportingTagModel(model);
}
void AddTagsLineEdit::setFilterModel(AlbumFilterModel* const model)
{
d->tagFilterModel = model;
d->completer->setTagFilterModel(d->tagFilterModel);
}
void AddTagsLineEdit::setAlbumModels(TagModel* const model,
TagPropertiesFilterModel* const filteredModel,
AlbumFilterModel* const filterModel)
{
if (filterModel)
{
setFilterModel(filterModel);
}
else if (filteredModel)
{
setFilterModel(filteredModel);
}
setSupportingTagModel(model);
}
void AddTagsLineEdit::setTagTreeView(TagTreeView* const view)
{
if (d->tagView)
{
disconnect(d->tagView, &TagTreeView::currentAlbumChanged, this,
&AddTagsLineEdit::setParentTag);
}
d->tagView = view;
if (d->tagView)
{
connect(d->tagView, &TagTreeView::currentAlbumChanged, this,
&AddTagsLineEdit::setParentTag);<--- You might need to cast the function pointer here
setParentTag(d->tagView->currentAlbum());
}
}
void AddTagsLineEdit::setCurrentTag(TAlbum* const album)<--- Either there is a missing override/final keyword, or the parameter 'album' can be declared as pointer to const
{
setCurrentTaggingAction(album ? TaggingAction(album->id()) : TaggingAction());
setText(album ? album->title() : QString());
}
void AddTagsLineEdit::setParentTag(Album* const album)<--- Either there is a missing override/final keyword, or the parameter 'album' can be declared as pointer to const
{
d->parentTagId = album ? album->id() : 0;
d->completer->setContextParentTag(d->parentTagId);
}
void AddTagsLineEdit::setAllowExceedBound(bool value)
{
Q_UNUSED(value);
// -> the pop-up is allowed to be bigger than the line edit widget
// Currently unimplemented, QCompleter calculates the size automatically.
// Idea: intercept show event via event filter on completer->popup(); from there, change width.
}
/**
* Tagging action is used by facemanagement and assignwidget
*/
void AddTagsLineEdit::slotReturnPressed()
{
d->returnPressed = true;
if (text().isEmpty())
{
//focus back to mainview
Q_EMIT taggingActionFinished();
}
else
{
Q_EMIT taggingActionActivated(currentTaggingAction());
}
}
void AddTagsLineEdit::slotEditingFinished()
{
//d->currentTaggingAction = TaggingAction();
}
void AddTagsLineEdit::slotTextEdited(const QString& text)
{
d->currentTaggingAction = TaggingAction();
d->returnPressed = false;
if (text.isEmpty())
{
Q_EMIT taggingActionSelected(TaggingAction());
}
else
{
Q_EMIT taggingActionSelected(TaggingActionFactory::defaultTaggingAction(text, d->parentTagId));
}
d->completer->update(text);
}
void AddTagsLineEdit::completerActivated(const TaggingAction& action)
{
if (!d->returnPressed)
{
setCurrentTaggingAction(action);
Q_EMIT taggingActionActivated(action);
}
}
void AddTagsLineEdit::completerHighlighted(const TaggingAction& action)
{
setCurrentTaggingAction(action);
}
void AddTagsLineEdit::setCurrentTaggingAction(const TaggingAction& action)
{
d->currentTaggingAction = action;
Q_EMIT taggingActionSelected(action);
}
TaggingAction AddTagsLineEdit::currentTaggingAction() const
{
if (d->currentTaggingAction.isValid())
{
return d->currentTaggingAction;
}
else if (text().isEmpty())
{
return TaggingAction();
}
return TaggingActionFactory::defaultTaggingAction(text(), d->parentTagId);
}
} // namespace Digikam
#include "moc_addtagslineedit.cpp"
|