1 #include "mycheckboxcontainer.h"
\r
3 MyCheckBoxContainer * MyCheckBoxContainer::instance = 0;
\r
4 int MyCheckBoxContainer::instances = 0;
\r
6 MyCheckBoxContainer::MyCheckBoxContainer()
\r
9 qDebug() << "MyCheckBoxContainer instances:" << instances;
\r
10 sortToBottom = false;
\r
13 MyCheckBoxContainer::~MyCheckBoxContainer()
\r
16 qDebug() << "MyCheckBoxContainer instances left:" << instances;
\r
20 MyCheckBoxContainer * MyCheckBoxContainer::getInstance()
\r
24 instance = new MyCheckBoxContainer();
\r
29 void MyCheckBoxContainer::add(QString item)
\r
31 QStringList list = item.split("\n");
\r
32 foreach(QString item, list)
\r
34 if(item.length() > 0)
\r
36 MyCheckBox * checkBox;
\r
37 if(item.startsWith("!"))
\r
39 checkBox = new MyCheckBox(item.right(item.length()-1));
\r
40 checkBox->setChecked(true);
\r
44 checkBox = new MyCheckBox(item);
\r
46 connect(checkBox, SIGNAL(clicked()), this, SLOT(clickedAction()));
\r
47 checkBoxes.append(checkBox);
\r
50 sortCheckedToBottom();
\r
53 void MyCheckBoxContainer::set(QString item)
\r
59 void MyCheckBoxContainer::clear()
\r
61 foreach(MyCheckBox * item, checkBoxes)
\r
64 item->deleteLater();
\r
69 void MyCheckBoxContainer::sortCheckedToBottom()
\r
73 qDebug() << "Sort checked to bottom";
\r
74 QList<MyCheckBox * > tempList;
\r
75 QList<MyCheckBox * > tempListChecked;
\r
76 foreach(MyCheckBox * item, checkBoxes)
\r
78 if(item->isChecked())
\r
80 tempListChecked.append(item);
\r
84 tempList.append(item);
\r
88 checkBoxes.append(tempList);
\r
89 checkBoxes.append(tempListChecked);
\r
90 emit signalSorted();
\r
94 QList<MyCheckBox * > const & MyCheckBoxContainer::getCheckBoxes()
\r
99 QString MyCheckBoxContainer::getListText()
\r
101 QString listText("");
\r
102 foreach(MyCheckBox * item, checkBoxes)
\r
104 if(item->isChecked())
\r
106 listText.append("!");
\r
108 listText.append(item->text());
\r
109 listText.append("\n");
\r
114 void MyCheckBoxContainer::uncheckAll()
\r
116 foreach(MyCheckBox * item, checkBoxes)
\r
118 item->setChecked(false);
\r
122 void MyCheckBoxContainer::removeChecked()
\r
124 QMutableListIterator<MyCheckBox * > i(checkBoxes);
\r
125 while (i.hasNext())
\r
127 MyCheckBox * item = i.next();
\r
128 if (item->isChecked())
\r
130 item->setParent(0);
\r
131 item->deleteLater();
\r
137 void MyCheckBoxContainer::setSortCheckedToBottom(bool sortToBottom)
\r
139 this->sortToBottom = sortToBottom;
\r
140 sortCheckedToBottom();
\r
143 void MyCheckBoxContainer::clickedAction()
\r
145 qDebug() << "Clicked a MyCheckBox";
\r
146 sortCheckedToBottom();
\r