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
33 qDebug() << "add" << item;
\r
35 if(sortAlphabetically)
\r
37 int listSize = list.size();
\r
39 for(int i = 0; i < listSize; ++i)
\r
41 int list2Size = list2.size();
\r
42 for(int j = 0; j < list2Size; ++j)
\r
45 if(list[i].toUpper() > list2[j].toUpper())
\r
50 qDebug() << "append" << list[i];
\r
51 list2.append(list[i]);
\r
55 qDebug() << "list" << list;
\r
56 foreach(QString item, list)
\r
58 if(item.length() > 0)
\r
60 MyCheckBox * checkBox;
\r
61 if(item.startsWith("!"))
\r
63 checkBox = new MyCheckBox(item.right(item.length()-1));
\r
64 checkBox->setChecked(true);
\r
68 checkBox = new MyCheckBox(item);
\r
70 connect(checkBox, SIGNAL(clicked()), this, SLOT(clickedAction()));
\r
71 checkBoxes.append(checkBox);
\r
74 sortCheckedToBottom();
\r
77 void MyCheckBoxContainer::set(QString item)
\r
80 qDebug() << "set" << item;
\r
84 void MyCheckBoxContainer::clear()
\r
86 foreach(MyCheckBox * item, checkBoxes)
\r
89 item->deleteLater();
\r
94 void MyCheckBoxContainer::sortCheckedToBottom()
\r
98 qDebug() << "Sort checked to bottom";
\r
99 QList<MyCheckBox * > tempList;
\r
100 QList<MyCheckBox * > tempListChecked;
\r
101 foreach(MyCheckBox * item, checkBoxes)
\r
103 if(item->isChecked())
\r
105 if(sortAlphabetically)
\r
107 int size = tempListChecked.size();
\r
109 for(pos = 0; pos < size; ++pos)
\r
111 if(tempListChecked[pos]->text().toUpper() > item->text().toUpper())
\r
116 tempListChecked.insert(pos, item);
\r
120 tempListChecked.append(item);
\r
125 if(sortAlphabetically)
\r
127 int size = tempList.size();
\r
129 for(pos = 0; pos < size; ++pos)
\r
131 if(tempList[pos]->text().toUpper() > item->text().toUpper())
\r
136 tempList.insert(pos, item);
\r
140 tempList.append(item);
\r
144 checkBoxes.clear();
\r
145 checkBoxes.append(tempList);
\r
146 checkBoxes.append(tempListChecked);
\r
148 emit signalSorted();
\r
151 QList<MyCheckBox * > const & MyCheckBoxContainer::getCheckBoxes()
\r
156 QString MyCheckBoxContainer::getListText()
\r
158 QString listText("");
\r
159 foreach(MyCheckBox * item, checkBoxes)
\r
161 if(item->isChecked())
\r
163 listText.append("!");
\r
165 listText.append(item->text());
\r
166 listText.append("\n");
\r
171 void MyCheckBoxContainer::uncheckAll()
\r
173 foreach(MyCheckBox * item, checkBoxes)
\r
175 item->setChecked(false);
\r
177 if(sortAlphabetically)
\r
179 set(getListText());
\r
183 void MyCheckBoxContainer::removeChecked()
\r
185 QMutableListIterator<MyCheckBox * > i(checkBoxes);
\r
186 while (i.hasNext())
\r
188 MyCheckBox * item = i.next();
\r
189 if (item->isChecked())
\r
191 item->setParent(0);
\r
192 item->deleteLater();
\r
198 void MyCheckBoxContainer::setSortCheckedToBottom(bool sortToBottom)
\r
200 this->sortToBottom = sortToBottom;
\r
201 sortCheckedToBottom();
\r
204 void MyCheckBoxContainer::setSortAlphabetically(bool sortAlphabetically)
\r
206 this->sortAlphabetically = sortAlphabetically;
\r
207 if(sortAlphabetically)
\r
209 set(getListText());
\r
213 void MyCheckBoxContainer::clickedAction()
\r
215 qDebug() << "Clicked a MyCheckBox";
\r
216 sortCheckedToBottom();
\r