1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtGui module of the Qt eXTension library
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
21 ** <http://libqxt.sourceforge.net> <foundation@libqxt.org>
23 ****************************************************************************/
24 #include "qxtlistwidgetitem.h"
25 #include "qxtlistwidget.h"
28 \class QxtListWidgetItem QxtListWidgetItem
30 \brief An extended QListWidgetItem.
32 QxtListWidgetItem provides means for offering check state change signals and
33 convenience methods for testing and setting flags.
39 QxtListWidgetItem::QxtListWidgetItem(QListWidget* parent, int type)
40 : QListWidgetItem(parent, type)
43 QxtListWidgetItem::QxtListWidgetItem(const QString& text, QListWidget* parent, int type)
44 : QListWidgetItem(text, parent, type)
47 QxtListWidgetItem::QxtListWidgetItem(const QIcon& icon, const QString& text, QListWidget* parent, int type)
48 : QListWidgetItem(icon, text, parent, type)
51 QxtListWidgetItem::QxtListWidgetItem(const QxtListWidgetItem& other)
52 : QListWidgetItem(other)
55 QxtListWidgetItem::~QxtListWidgetItem()
59 Returns \b true if the \a flag is set, otherwise \b false.
61 \sa setFlag(), QListWidgetItem::flags(), Qt::ItemFlag
63 bool QxtListWidgetItem::testFlag(Qt::ItemFlag flag) const
65 return (flags() & flag);
69 If \a enabled is \b true, the item \a flag is enabled; otherwise, it is disabled.
71 \sa testFlag(), QListWidgetItem::setFlags(), Qt::ItemFlag
73 void QxtListWidgetItem::setFlag(Qt::ItemFlag flag, bool enabled)
76 setFlags(flags() | flag);
78 setFlags(flags() & ~flag);
81 void QxtListWidgetItem::setData(int role, const QVariant& value)
83 if (role == Qt::CheckStateRole)
85 const Qt::CheckState newState = static_cast<Qt::CheckState>(value.toInt());
86 const Qt::CheckState oldState = static_cast<Qt::CheckState>(data(role).toInt());
88 QListWidgetItem::setData(role, value);
90 if (newState != oldState)
92 QxtListWidget* list = qobject_cast<QxtListWidget*>(listWidget());
95 emit list->itemCheckStateChanged(this);
101 QListWidgetItem::setData(role, value);