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 if(sortAlphabetically)
\r
37 foreach(QString item, list)
\r
39 if(item.length() > 0)
\r
41 MyCheckBox * checkBox;
\r
42 if(item.startsWith("!"))
\r
44 checkBox = new MyCheckBox(item.right(item.length()-1));
\r
45 checkBox->setChecked(true);
\r
49 checkBox = new MyCheckBox(item);
\r
51 connect(checkBox, SIGNAL(clicked()), this, SLOT(clickedAction()));
\r
52 checkBoxes.append(checkBox);
\r
55 sortCheckedToBottom();
\r
58 void MyCheckBoxContainer::set(QString item)
\r
65 void MyCheckBoxContainer::clear()
\r
67 foreach(MyCheckBox * item, checkBoxes)
\r
70 item->deleteLater();
\r
75 void MyCheckBoxContainer::sortCheckedToBottom()
\r
79 qDebug() << "Sort checked to bottom";
\r
80 QList<MyCheckBox * > tempList;
\r
81 QList<MyCheckBox * > tempListChecked;
\r
82 foreach(MyCheckBox * item, checkBoxes)
\r
84 if(item->isChecked())
\r
86 if(sortAlphabetically)
\r
88 int size = tempListChecked.size();
\r
90 for(pos = 0; pos < size; ++pos)
\r
92 if(tempListChecked[pos]->text() > item->text())
\r
97 tempListChecked.insert(pos, item);
\r
101 tempListChecked.append(item);
\r
106 if(sortAlphabetically)
\r
108 int size = tempList.size();
\r
110 for(pos = 0; pos < size; ++pos)
\r
112 if(tempList[pos]->text() > item->text())
\r
117 tempList.insert(pos, item);
\r
121 tempList.append(item);
\r
125 checkBoxes.clear();
\r
126 checkBoxes.append(tempList);
\r
127 checkBoxes.append(tempListChecked);
\r
128 emit signalSorted();
\r
132 QList<MyCheckBox * > const & MyCheckBoxContainer::getCheckBoxes()
\r
137 QString MyCheckBoxContainer::getListText()
\r
139 QString listText("");
\r
140 foreach(MyCheckBox * item, checkBoxes)
\r
142 if(item->isChecked())
\r
144 listText.append("!");
\r
146 listText.append(item->text());
\r
147 listText.append("\n");
\r
152 void MyCheckBoxContainer::uncheckAll()
\r
154 foreach(MyCheckBox * item, checkBoxes)
\r
156 item->setChecked(false);
\r
158 if(sortAlphabetically)
\r
160 set(getListText());
\r
164 void MyCheckBoxContainer::removeChecked()
\r
166 QMutableListIterator<MyCheckBox * > i(checkBoxes);
\r
167 while (i.hasNext())
\r
169 MyCheckBox * item = i.next();
\r
170 if (item->isChecked())
\r
172 item->setParent(0);
\r
173 item->deleteLater();
\r
179 void MyCheckBoxContainer::setSortCheckedToBottom(bool sortToBottom)
\r
181 this->sortToBottom = sortToBottom;
\r
182 sortCheckedToBottom();
\r
185 void MyCheckBoxContainer::setSortAlphabetically(bool sortAlphabetically)
\r
187 this->sortAlphabetically = sortAlphabetically;
\r
188 if(sortAlphabetically)
\r
190 set(getListText());
\r
194 void MyCheckBoxContainer::clickedAction()
\r
196 qDebug() << "Clicked a MyCheckBox";
\r
197 sortCheckedToBottom();
\r