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
11 sortAlphabetically = false;
\r
14 MyCheckBoxContainer::~MyCheckBoxContainer()
\r
17 qDebug() << "MyCheckBoxContainer instances left:" << instances;
\r
21 MyCheckBoxContainer * MyCheckBoxContainer::getInstance()
\r
25 instance = new MyCheckBoxContainer();
\r
30 void MyCheckBoxContainer::add(QString item)
\r
32 QStringList list = item.split("\n");
\r
34 if(sortAlphabetically)
\r
36 int listSize = list.size();
\r
38 for(int i = 0; i < listSize; ++i)
\r
40 int list2Size = list2.size();
\r
41 for(int j = 0; j < list2Size; ++j)
\r
44 if(list[i].toUpper() > list2[j].toUpper())
\r
49 list2.append(list[i]);
\r
53 foreach(QString item, list)
\r
55 if(item.length() > 0)
\r
57 MyCheckBox * checkBox;
\r
58 if(item.startsWith("!"))
\r
60 checkBox = new MyCheckBox(item.right(item.length()-1));
\r
61 checkBox->setChecked(true);
\r
65 checkBox = new MyCheckBox(item);
\r
67 connect(checkBox, SIGNAL(clicked()), this, SLOT(clickedAction()));
\r
68 checkBoxes.append(checkBox);
\r
71 sortCheckedToBottom();
\r
74 void MyCheckBoxContainer::set(QString item)
\r
81 void MyCheckBoxContainer::clear()
\r
83 foreach(MyCheckBox * item, checkBoxes)
\r
86 item->deleteLater();
\r
91 void MyCheckBoxContainer::sortCheckedToBottom()
\r
95 qDebug() << "Sort checked to bottom";
\r
96 QList<MyCheckBox * > tempList;
\r
97 QList<MyCheckBox * > tempListChecked;
\r
98 foreach(MyCheckBox * item, checkBoxes)
\r
100 if(item->isChecked())
\r
102 if(sortAlphabetically)
\r
104 int size = tempListChecked.size();
\r
106 for(pos = 0; pos < size; ++pos)
\r
108 if(tempListChecked[pos]->text().toUpper() > item->text().toUpper())
\r
113 tempListChecked.insert(pos, item);
\r
117 tempListChecked.append(item);
\r
122 if(sortAlphabetically)
\r
124 int size = tempList.size();
\r
126 for(pos = 0; pos < size; ++pos)
\r
128 if(tempList[pos]->text().toUpper() > item->text().toUpper())
\r
133 tempList.insert(pos, item);
\r
137 tempList.append(item);
\r
141 checkBoxes.clear();
\r
142 checkBoxes.append(tempList);
\r
143 checkBoxes.append(tempListChecked);
\r
144 emit signalSorted();
\r
148 QList<MyCheckBox * > const & MyCheckBoxContainer::getCheckBoxes()
\r
153 QString MyCheckBoxContainer::getListText()
\r
155 QString listText("");
\r
156 foreach(MyCheckBox * item, checkBoxes)
\r
158 if(item->isChecked())
\r
160 listText.append("!");
\r
162 listText.append(item->text());
\r
163 listText.append("\n");
\r
168 void MyCheckBoxContainer::uncheckAll()
\r
170 foreach(MyCheckBox * item, checkBoxes)
\r
172 item->setChecked(false);
\r
174 if(sortAlphabetically)
\r
176 set(getListText());
\r
180 void MyCheckBoxContainer::removeChecked()
\r
182 QMutableListIterator<MyCheckBox * > i(checkBoxes);
\r
183 while (i.hasNext())
\r
185 MyCheckBox * item = i.next();
\r
186 if (item->isChecked())
\r
188 item->setParent(0);
\r
189 item->deleteLater();
\r
195 void MyCheckBoxContainer::setSortCheckedToBottom(bool sortToBottom)
\r
197 this->sortToBottom = sortToBottom;
\r
198 sortCheckedToBottom();
\r
201 void MyCheckBoxContainer::setSortAlphabetically(bool sortAlphabetically)
\r
203 this->sortAlphabetically = sortAlphabetically;
\r
204 if(sortAlphabetically)
\r
206 set(getListText());
\r
210 void MyCheckBoxContainer::clickedAction()
\r
212 qDebug() << "Clicked a MyCheckBox";
\r
213 sortCheckedToBottom();
\r