LeechCraft 0.6.70-19424-g027e980fd1
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>
11#include <QLineEdit>
13#include "tagseditoraddon.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 QLineEdit { parent };
26 new TagsEditorAddon { *edit, ITM_ };
27 edit->setFrame (false);
28 setEditorData (edit, index);
29 return edit;
30 }
31
32 void TagsEditDelegate::paint (QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
33 {
34 auto opt = option;
35 initStyleOption (&opt, index);
36 opt.text = ITM_.Join (index.data ().toStringList ());
37
38 const auto style = opt.widget ? opt.widget->style () : QApplication::style ();
39 style->drawControl (QStyle::CE_ItemViewItem, &opt, painter);
40 }
41
42 void TagsEditDelegate::setEditorData (QWidget *editor, const QModelIndex& index) const
43 {
44 const auto& tags = index.data (Qt::EditRole).toStringList ();
45 qobject_cast<QLineEdit*> (editor)->setText (ITM_.Join (tags));
46 }
47
48 void TagsEditDelegate::setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const
49 {
50 const auto& tags = ITM_.Split (qobject_cast<QLineEdit*> (editor)->text ());
51 model->setData (index, tags, Qt::EditRole);
52 }
53}
Tags manager's interface.
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
Makes a QLineEdit edit a list of tags.