Ok, the long awaited config wizard is here (at least in a very basic state). There...
[quassel.git] / src / contrib / libqxt-2007-10-24 / src / gui / qxttablewidgetitem.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 "qxttablewidgetitem.h"
25 #include "qxttablewidget.h"
26
27 /*!
28     \class QxtTableWidgetItem QxtTableWidgetItem
29     \ingroup QxtGui
30     \brief An extended QTableWidgetItem.
31
32     QxtTableWidgetItem provides means for offering check state change signals and
33     convenience methods for testing and setting flags.
34
35     \sa QxtTableWidget
36  */
37
38
39 QxtTableWidgetItem::QxtTableWidgetItem(int type)
40         : QTableWidgetItem(type)
41 {}
42
43 QxtTableWidgetItem::QxtTableWidgetItem(const QString& text, int type)
44         : QTableWidgetItem(text, type)
45 {}
46
47 QxtTableWidgetItem::QxtTableWidgetItem(const QIcon& icon, const QString& text, int type)
48         : QTableWidgetItem(text, type)
49 {
50     setIcon(icon); // for 4.1 compatibility
51 }
52
53 QxtTableWidgetItem::QxtTableWidgetItem(const QTableWidgetItem& other)
54         : QTableWidgetItem(other)
55 {}
56
57 QxtTableWidgetItem::~QxtTableWidgetItem()
58 {}
59
60 /*!
61     Returns \b true if the \a flag is set, otherwise \b false.
62
63     \sa setFlag(), QTableWidgetItem::flags(), Qt::ItemFlag
64  */
65 bool QxtTableWidgetItem::testFlag(Qt::ItemFlag flag) const
66 {
67     return (flags() & flag);
68 }
69
70 /*!
71     If \a enabled is \b true, the item \a flag is enabled; otherwise, it is disabled.
72
73     \sa testFlag(), QTableWidgetItem::setFlags(), Qt::ItemFlag
74  */
75 void QxtTableWidgetItem::setFlag(Qt::ItemFlag flag, bool enabled)
76 {
77     if (enabled)
78         setFlags(flags() | flag);
79     else
80         setFlags(flags() & ~flag);
81 }
82
83 void QxtTableWidgetItem::setData(int role, const QVariant& value)
84 {
85     if (role == Qt::CheckStateRole)
86     {
87         const Qt::CheckState newState = static_cast<Qt::CheckState>(value.toInt());
88         const Qt::CheckState oldState = static_cast<Qt::CheckState>(data(role).toInt());
89
90         QTableWidgetItem::setData(role, value);
91
92         if (newState != oldState)
93         {
94             QxtTableWidget* table = qobject_cast<QxtTableWidget*>(tableWidget());
95             if (table)
96             {
97                 emit table->itemCheckStateChanged(this);
98             }
99         }
100     }
101     else
102     {
103         QTableWidgetItem::setData(role, value);
104     }
105 }