LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
tagseditdelegate.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#include "
tagseditdelegate.h
"
10
#include <QApplication>
11
#include <
interfaces/core/itagsmanager.h
>
12
#include "
tagscompleter.h
"
13
#include "
tagslineedit.h
"
14
15
namespace
LC::Util
16
{
17
TagsEditDelegate::TagsEditDelegate
(
ITagsManager
& itm, QObject *parent)
18
: QStyledItemDelegate { parent }
19
, ITM_ { itm }
20
{
21
}
22
23
QWidget*
TagsEditDelegate::createEditor
(QWidget *parent,
const
QStyleOptionViewItem&,
const
QModelIndex& index)
const
24
{
25
const
auto
edit =
new
TagsLineEdit
{ parent };
26
new
TagsCompleter
{ edit };
27
edit->AddSelector ();
28
edit->setFrame (
false
);
29
setEditorData
(edit, index);
30
return
edit;
31
}
32
33
void
TagsEditDelegate::paint
(QPainter *painter,
const
QStyleOptionViewItem& option,
const
QModelIndex& index)
const
34
{
35
auto
opt = option;
36
initStyleOption (&opt, index);
37
opt.text = ITM_.Join (index.data ().toStringList ());
38
39
const
auto
style = opt.widget ? opt.widget->style () : QApplication::style ();
40
style->drawControl (QStyle::CE_ItemViewItem, &opt, painter);
41
}
42
43
void
TagsEditDelegate::setEditorData
(QWidget *editor,
const
QModelIndex& index)
const
44
{
45
const
auto
& tags = index.data (Qt::EditRole).toStringList ();
46
dynamic_cast<
TagsLineEdit
*
>
(editor)->setText (ITM_.Join (tags));
47
}
48
49
void
TagsEditDelegate::setModelData
(QWidget *editor, QAbstractItemModel *model,
const
QModelIndex& index)
const
50
{
51
const
auto
& tags = ITM_.Split (
dynamic_cast<
TagsLineEdit
*
>
(editor)->text ());
52
model->setData (index, tags, Qt::EditRole);
53
}
54
}
ITagsManager
Tags manager's interface.
Definition
itagsmanager.h:23
LC::Util::TagsCompleter
Completer suitable for tag completion.
Definition
tagscompleter.h:39
LC::Util::TagsEditDelegate::TagsEditDelegate
TagsEditDelegate(ITagsManager &, QObject *=nullptr)
Definition
tagseditdelegate.cpp:17
LC::Util::TagsEditDelegate::setEditorData
void setEditorData(QWidget *, const QModelIndex &) const override
Definition
tagseditdelegate.cpp:43
LC::Util::TagsEditDelegate::setModelData
void setModelData(QWidget *, QAbstractItemModel *, const QModelIndex &) const override
Definition
tagseditdelegate.cpp:49
LC::Util::TagsEditDelegate::createEditor
QWidget * createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override
Definition
tagseditdelegate.cpp:23
LC::Util::TagsEditDelegate::paint
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override
Definition
tagseditdelegate.cpp:33
LC::Util::TagsLineEdit
A line edit class suitable for use with TagsCompleter.
Definition
tagslineedit.h:29
itagsmanager.h
LC::Util
Definition
icoreproxy.h:34
tagscompleter.h
tagseditdelegate.h
tagslineedit.h
src
util
tags
tagseditdelegate.cpp
Generated by
1.17.0