00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) Qxt Foundation. Some rights reserved. 00004 ** 00005 ** This file is part of the QxtGui module of the Qxt library. 00006 ** 00007 ** This library is free software; you can redistribute it and/or modify it 00008 ** under the terms of the Common Public License, version 1.0, as published 00009 ** by IBM, and/or under the terms of the GNU Lesser General Public License, 00010 ** version 2.1, as published by the Free Software Foundation. 00011 ** 00012 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY 00013 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY 00014 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR 00015 ** FITNESS FOR A PARTICULAR PURPOSE. 00016 ** 00017 ** You should have received a copy of the CPL and the LGPL along with this 00018 ** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files 00019 ** included with the source distribution for more information. 00020 ** If you did not receive a copy of the licenses, contact the Qxt Foundation. 00021 ** 00022 ** <http://libqxt.org> <foundation@libqxt.org> 00023 ** 00024 ****************************************************************************/ 00025 #include "qxttablewidgetitem.h" 00026 #include "qxttablewidget.h" 00027 00040 QxtTableWidgetItem::QxtTableWidgetItem(int type) 00041 : QTableWidgetItem(type) 00042 {} 00043 00044 QxtTableWidgetItem::QxtTableWidgetItem(const QString& text, int type) 00045 : QTableWidgetItem(text, type) 00046 {} 00047 00048 QxtTableWidgetItem::QxtTableWidgetItem(const QIcon& icon, const QString& text, int type) 00049 : QTableWidgetItem(text, type) 00050 { 00051 setIcon(icon); // for 4.1 compatibility 00052 } 00053 00054 QxtTableWidgetItem::QxtTableWidgetItem(const QTableWidgetItem& other) 00055 : QTableWidgetItem(other) 00056 {} 00057 00058 QxtTableWidgetItem::~QxtTableWidgetItem() 00059 {} 00060 00066 bool QxtTableWidgetItem::testFlag(Qt::ItemFlag flag) const 00067 { 00068 return (flags() & flag); 00069 } 00070 00076 void QxtTableWidgetItem::setFlag(Qt::ItemFlag flag, bool enabled) 00077 { 00078 if (enabled) 00079 setFlags(flags() | flag); 00080 else 00081 setFlags(flags() & ~flag); 00082 } 00083 00087 void QxtTableWidgetItem::setData(int role, const QVariant& value) 00088 { 00089 if (role == Qt::CheckStateRole) 00090 { 00091 const Qt::CheckState newState = static_cast<Qt::CheckState>(value.toInt()); 00092 const Qt::CheckState oldState = static_cast<Qt::CheckState>(data(role).toInt()); 00093 00094 QTableWidgetItem::setData(role, value); 00095 00096 if (newState != oldState) 00097 { 00098 QxtTableWidget* table = qobject_cast<QxtTableWidget*>(tableWidget()); 00099 if (table) 00100 { 00101 emit table->itemCheckStateChanged(this); 00102 } 00103 } 00104 } 00105 else 00106 { 00107 QTableWidgetItem::setData(role, value); 00108 } 00109 }