LeechCraft 0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
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>
12#include "tagscompleter.h"
13#include "tagslineedit.h"
14
15namespace LC::Util
16{
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}
Tags manager's interface.
Completer suitable for tag completion.
TagsEditDelegate(ITagsManager &, QObject *=nullptr)
void setEditorData(QWidget *, const QModelIndex &) const override
void setModelData(QWidget *, QAbstractItemModel *, const QModelIndex &) const override
QWidget * createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override
A line edit class suitable for use with TagsCompleter.