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 "qxttablewidgetitem.h"
25 #include "qxttablewidget.h"
28 \class QxtTableWidgetItem QxtTableWidgetItem
30 \brief An extended QTableWidgetItem.
32 QxtTableWidgetItem provides means for offering check state change signals and
33 convenience methods for testing and setting flags.
39 QxtTableWidgetItem::QxtTableWidgetItem(int type)
40 : QTableWidgetItem(type)
43 QxtTableWidgetItem::QxtTableWidgetItem(const QString& text, int type)
44 : QTableWidgetItem(text, type)
47 QxtTableWidgetItem::QxtTableWidgetItem(const QIcon& icon, const QString& text, int type)
48 : QTableWidgetItem(text, type)
50 setIcon(icon); // for 4.1 compatibility
53 QxtTableWidgetItem::QxtTableWidgetItem(const QTableWidgetItem& other)
54 : QTableWidgetItem(other)
57 QxtTableWidgetItem::~QxtTableWidgetItem()
61 Returns \b true if the \a flag is set, otherwise \b false.
63 \sa setFlag(), QTableWidgetItem::flags(), Qt::ItemFlag
65 bool QxtTableWidgetItem::testFlag(Qt::ItemFlag flag) const
67 return (flags() & flag);
71 If \a enabled is \b true, the item \a flag is enabled; otherwise, it is disabled.
73 \sa testFlag(), QTableWidgetItem::setFlags(), Qt::ItemFlag
75 void QxtTableWidgetItem::setFlag(Qt::ItemFlag flag, bool enabled)
78 setFlags(flags() | flag);
80 setFlags(flags() & ~flag);
83 void QxtTableWidgetItem::setData(int role, const QVariant& value)
85 if (role == Qt::CheckStateRole)
87 const Qt::CheckState newState = static_cast<Qt::CheckState>(value.toInt());
88 const Qt::CheckState oldState = static_cast<Qt::CheckState>(data(role).toInt());
90 QTableWidgetItem::setData(role, value);
92 if (newState != oldState)
94 QxtTableWidget* table = qobject_cast<QxtTableWidget*>(tableWidget());
97 emit table->itemCheckStateChanged(this);
103 QTableWidgetItem::setData(role, value);