2
#include <QErrorMessage>
3
TreeModel::TreeModel() : m_messageBox(0)
11
m_messageBox = new QErrorMessage();
12
m_messageBox->showMessage("Changeme: If you deselect this, the result wont be submitted to Ubuntu Friendly!");
15
bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
17
QStandardItem *item = QStandardItemModel::itemFromIndex(index);
21
// do not warn when the item is checked
22
if ( value == QVariant(Qt::Unchecked) && role == Qt::CheckStateRole)
26
QStandardItemModel::setData(item->index(), value, role);
27
// we are a child, and we have to update parent's status
29
for(int i=0; i< item->parent()->rowCount(); i++) {
30
QStandardItem *childItem = item->parent()->child(i);
31
if (childItem->checkState() == Qt::Checked) {
35
if (selected == item->parent()->rowCount()) {
36
item->parent()->setCheckState(Qt::Checked);
37
} else if (selected == 0) {
38
item->parent()->setCheckState(Qt::Unchecked);
40
item->parent()->setCheckState(Qt::PartiallyChecked);
43
// if we dont have a parent, then we are root. Deselect/select children
44
for(int i=0; i< item->rowCount(); i++) {
45
QStandardItem *childItem = item->child(i);
46
QStandardItemModel::setData(childItem->index(), value, role);
49
return QStandardItemModel::setData(index, value, role);
52
void TreeModel::setInteraction(bool value)
54
for(int i=0; i< rowCount(); i++) {
55
QStandardItem *item = this->item(i, 0);
58
item->setEnabled(value);
59
for(int j=0; j< item->rowCount(); j++) {
60
QStandardItem *childItem = item->child(j);
63
childItem->setEnabled(value);
68
void TreeModel::selectAll(bool select)
70
Qt::CheckState state = select ? Qt::Checked : Qt::Unchecked;
71
for(int i=0; i< rowCount(); i++) {
72
QStandardItem *item = this->item(i, 0);
75
item->setCheckState(state);
76
for(int j=0; j< item->rowCount(); j++) {
77
QStandardItem *childItem = item->child(j);
80
childItem->setCheckState(state);