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 list2.append(list.takeFirst());
\r
37 int listSize = list.size();
\r
39 bool inserted = false;
\r
40 for(int i = 0; i < listSize; ++i)
\r
43 int list2Size = list2.size();
\r
44 for(int j = 0; j < list2Size; ++j)
\r
47 if(list[i].toUpper() < list2[j].toUpper())
\r
49 list2.insert(pos, list[i]);
\r
54 if(inserted == false)
\r
56 list2.append(list[i]);
\r
61 qDebug() << "list" << list;
\r
62 foreach(QString item, list)
\r
64 if(item.length() > 0)
\r
66 MyCheckBox * checkBox;
\r
67 if(item.startsWith("!"))
\r
69 checkBox = new MyCheckBox(item.right(item.length()-1));
\r
70 checkBox->setChecked(true);
\r
74 checkBox = new MyCheckBox(item);
\r
76 connect(checkBox, SIGNAL(clicked()), this, SLOT(clickedAction()));
\r
77 checkBoxes.append(checkBox);
\r
80 sortCheckedToBottom();
\r
83 void MyCheckBoxContainer::set(QString item)
\r
89 void MyCheckBoxContainer::clear()
\r
91 foreach(MyCheckBox * item, checkBoxes)
\r
94 item->deleteLater();
\r
99 void MyCheckBoxContainer::sortCheckedToBottom()
\r
103 qDebug() << "Sort checked to bottom";
\r
104 QList<MyCheckBox * > tempList;
\r
105 QList<MyCheckBox * > tempListChecked;
\r
106 foreach(MyCheckBox * item, checkBoxes)
\r
108 if(item->isChecked())
\r
110 if(sortAlphabetically)
\r
112 int size = tempListChecked.size();
\r
114 for(pos = 0; pos < size; ++pos)
\r
116 if(tempListChecked[pos]->text().toUpper() > item->text().toUpper())
\r
121 tempListChecked.insert(pos, item);
\r
125 tempListChecked.append(item);
\r
130 if(sortAlphabetically)
\r
132 int size = tempList.size();
\r
134 for(pos = 0; pos < size; ++pos)
\r
136 if(tempList[pos]->text().toUpper() > item->text().toUpper())
\r
141 tempList.insert(pos, item);
\r
145 tempList.append(item);
\r
149 checkBoxes.clear();
\r
150 checkBoxes.append(tempList);
\r
151 checkBoxes.append(tempListChecked);
\r
153 emit signalSorted();
\r
156 QList<MyCheckBox * > const & MyCheckBoxContainer::getCheckBoxes()
\r
161 QString MyCheckBoxContainer::getListText()
\r
163 QString listText("");
\r
164 foreach(MyCheckBox * item, checkBoxes)
\r
166 if(item->isChecked())
\r
168 listText.append("!");
\r
170 listText.append(item->text());
\r
171 listText.append("\n");
\r
176 void MyCheckBoxContainer::uncheckAll()
\r
178 foreach(MyCheckBox * item, checkBoxes)
\r
180 item->setChecked(false);
\r
182 if(sortAlphabetically)
\r
184 set(getListText());
\r
188 void MyCheckBoxContainer::removeChecked()
\r
190 QMutableListIterator<MyCheckBox * > i(checkBoxes);
\r
191 while (i.hasNext())
\r
193 MyCheckBox * item = i.next();
\r
194 if (item->isChecked())
\r
196 item->setParent(0);
\r
197 item->deleteLater();
\r
203 void MyCheckBoxContainer::setSortCheckedToBottom(bool sortToBottom)
\r
205 this->sortToBottom = sortToBottom;
\r
206 sortCheckedToBottom();
\r
209 void MyCheckBoxContainer::setSortAlphabetically(bool sortAlphabetically)
\r
211 this->sortAlphabetically = sortAlphabetically;
\r
212 if(sortAlphabetically)
\r
214 set(getListText());
\r
218 void MyCheckBoxContainer::clickedAction()
\r
220 qDebug() << "Clicked a MyCheckBox";
\r
221 sortCheckedToBottom();
\r