76cc156eea154b3e9656e82cf5a8e8e19261c79e
[quassel.git] / src / contrib / libqxt-2007-10-24 / src / gui / qxtlistwidgetitem.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
4 **
5 ** This file is part of the QxtGui module of the Qt eXTension library
6 **
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
9 ** IBM.
10 **
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.
15 **
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.
20 **
21 ** <http://libqxt.sourceforge.net>  <foundation@libqxt.org>
22 **
23 ****************************************************************************/
24 #include "qxtlistwidgetitem.h"
25 #include "qxtlistwidget.h"
26
27 /*!
28     \class QxtListWidgetItem QxtListWidgetItem
29     \ingroup QxtGui
30     \brief An extended QListWidgetItem.
31
32     QxtListWidgetItem provides means for offering check state change signals and
33     convenience methods for testing and setting flags.
34
35     \sa QxtListWidget
36  */
37
38
39 QxtListWidgetItem::QxtListWidgetItem(QListWidget* parent, int type)
40         : QListWidgetItem(parent, type)
41 {}
42
43 QxtListWidgetItem::QxtListWidgetItem(const QString& text, QListWidget* parent, int type)
44         : QListWidgetItem(text, parent, type)
45 {}
46
47 QxtListWidgetItem::QxtListWidgetItem(const QIcon& icon, const QString& text, QListWidget* parent, int type)
48         : QListWidgetItem(icon, text, parent, type)
49 {}
50
51 QxtListWidgetItem::QxtListWidgetItem(const QxtListWidgetItem& other)
52         : QListWidgetItem(other)
53 {}
54
55 QxtListWidgetItem::~QxtListWidgetItem()
56 {}
57
58 /*!
59     Returns \b true if the \a flag is set, otherwise \b false.
60
61     \sa setFlag(), QListWidgetItem::flags(), Qt::ItemFlag
62  */
63 bool QxtListWidgetItem::testFlag(Qt::ItemFlag flag) const
64 {
65     return (flags() & flag);
66 }
67
68 /*!
69     If \a enabled is \b true, the item \a flag is enabled; otherwise, it is disabled.
70
71     \sa testFlag(), QListWidgetItem::setFlags(), Qt::ItemFlag
72  */
73 void QxtListWidgetItem::setFlag(Qt::ItemFlag flag, bool enabled)
74 {
75     if (enabled)
76         setFlags(flags() | flag);
77     else
78         setFlags(flags() & ~flag);
79 }
80
81 void QxtListWidgetItem::setData(int role, const QVariant& value)
82 {
83     if (role == Qt::CheckStateRole)
84     {
85         const Qt::CheckState newState = static_cast<Qt::CheckState>(value.toInt());
86         const Qt::CheckState oldState = static_cast<Qt::CheckState>(data(role).toInt());
87
88         QListWidgetItem::setData(role, value);
89
90         if (newState != oldState)
91         {
92             QxtListWidget* list = qobject_cast<QxtListWidget*>(listWidget());
93             if (list)
94             {
95                 emit list->itemCheckStateChanged(this);
96             }
97         }
98     }
99     else
100     {
101         QListWidgetItem::setData(role, value);
102     }
103 }