Added sort alphabetically. Changed Checked bottom to Checked to bottom.
[easylist] / src / mycheckboxcontainer.cpp
index 5296f17..edcab32 100755 (executable)
@@ -8,6 +8,7 @@ MyCheckBoxContainer::MyCheckBoxContainer()
     ++instances;\r
     qDebug() << "MyCheckBoxContainer instances:" << instances;\r
     sortToBottom = false;\r
+    sortAlphabetically = false;\r
 }\r
 \r
 MyCheckBoxContainer::~MyCheckBoxContainer()\r
@@ -29,6 +30,10 @@ MyCheckBoxContainer * MyCheckBoxContainer::getInstance()
 void MyCheckBoxContainer::add(QString item)\r
 {\r
     QStringList list = item.split("\n");\r
+    if(sortAlphabetically)\r
+    {\r
+        list.sort();\r
+    }\r
     foreach(QString item, list)\r
     {\r
         if(item.length() > 0)\r
@@ -52,6 +57,7 @@ void MyCheckBoxContainer::add(QString item)
 \r
 void MyCheckBoxContainer::set(QString item)\r
 {\r
+    qDebug() << item;\r
     clear();\r
     add(item);\r
 }\r
@@ -77,11 +83,43 @@ void MyCheckBoxContainer::sortCheckedToBottom()
         {\r
             if(item->isChecked())\r
             {\r
-                tempListChecked.append(item);\r
+                if(sortAlphabetically)\r
+                {\r
+                    int size = tempListChecked.size();\r
+                    int pos = 0;\r
+                    for(pos = 0; pos < size; ++pos)\r
+                    {\r
+                        if(tempListChecked[pos]->text() > item->text())\r
+                        {\r
+                            break;\r
+                        }\r
+                    }\r
+                    tempListChecked.insert(pos, item);\r
+                }\r
+                else\r
+                {\r
+                    tempListChecked.append(item);\r
+                }\r
             }\r
             else\r
             {\r
-                tempList.append(item);\r
+                if(sortAlphabetically)\r
+                {\r
+                    int size = tempList.size();\r
+                    int pos = 0;\r
+                    for(pos = 0; pos < size; ++pos)\r
+                    {\r
+                        if(tempList[pos]->text() > item->text())\r
+                        {\r
+                            break;\r
+                        }\r
+                    }\r
+                    tempList.insert(pos, item);\r
+                }\r
+                else\r
+                {\r
+                    tempList.append(item);\r
+                }\r
             }\r
         }\r
         checkBoxes.clear();\r
@@ -117,6 +155,10 @@ void MyCheckBoxContainer::uncheckAll()
     {\r
         item->setChecked(false);\r
     }\r
+    if(sortAlphabetically)\r
+    {\r
+        set(getListText());\r
+    }\r
 }\r
 \r
 void MyCheckBoxContainer::removeChecked()\r
@@ -140,6 +182,15 @@ void MyCheckBoxContainer::setSortCheckedToBottom(bool sortToBottom)
     sortCheckedToBottom();\r
 }\r
 \r
+void MyCheckBoxContainer::setSortAlphabetically(bool sortAlphabetically)\r
+{\r
+    this->sortAlphabetically = sortAlphabetically;\r
+    if(sortAlphabetically)\r
+    {\r
+        set(getListText());\r
+    }\r
+}\r
+\r
 void MyCheckBoxContainer::clickedAction()\r
 {\r
     qDebug() << "Clicked a MyCheckBox";\r