+ * Prefix all checked items with ! in the list text and save it to QSettings.\r
+ */\r
+void MainWindow::slotListWindowSaveChecked()\r
+{\r
+ qDebug() << "Save selected";\r
+ QString listText("");\r
+ foreach(QCheckBox * cb, checkBoxes)\r
+ {\r
+ QString item(cb->text());\r
+ if(cb->isChecked() == true)\r
+ {\r
+ if(item.startsWith("!") == false)\r
+ {\r
+ item.push_front("!");\r
+ }\r
+ listText.append(item);\r
+ }\r
+ else\r
+ {\r
+ if(item.startsWith("!") == true)\r
+ {\r
+ item = item.replace("!", "");\r
+ }\r
+ listText.append(item);\r
+ }\r
+ listText.append("\n");\r
+ }\r
+\r
+ settings->setValue(LIST_TEXT, listText);\r
+}\r
+\r
+/**\r
+ * Is called when a checkbox has been clicked.\r
+ *\r
+ * @fn slotActionCheckBox\r
+ * @param bool checked - true if checkbox is checked.\r
+ */\r
+void MainWindow::slotActionCheckBox(bool checked)\r
+{\r
+ qDebug() << "CheckBox checked=" << checked;\r
+ slotListWindowSaveChecked();\r
+ if(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool())\r
+ {\r
+ slotSortCheckedBottom();\r
+ // Remove all the checkboxes from the screen.\r
+ foreach(QCheckBox * cb, checkBoxes)\r
+ {\r
+ cb->deleteLater();\r
+ }\r
+ generateList();\r
+ }\r
+ else\r
+ {\r
+ qDebug() << "No need to sort items to bottom";\r
+ }\r
+}\r
+\r
+/**\r
+ * Sort checked items to bottom of the list text and returns the new list text.\r
+ *\r
+ * @fn slotSortCheckedBottom\r
+ *\r
+ * @return QString - the new list text.\r
+ */\r
+QString MainWindow::slotSortCheckedBottom()\r
+{\r
+ QString result(settings->value(LIST_TEXT).toString());\r
+ if(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool())\r
+ {\r
+ QStringList list = result.split("\n");\r
+ QString listText("");\r
+ QString checkedListText("");\r
+ foreach(QString item, list)\r
+ {\r
+ if(item.length() > 0)\r
+ {\r
+ if(item.startsWith("!"))\r
+ {\r
+ checkedListText.append(item);\r
+ checkedListText.append("\n");\r
+ }\r
+ else\r
+ {\r
+ listText.append(item);\r
+ listText.append("\n");\r
+ }\r
+ }\r
+ }\r
+ listText.append(checkedListText);\r
+ qDebug() << "Sort checked items to bottom";\r
+ settings->setValue(LIST_TEXT, listText);\r
+ result = listText;\r
+ }\r
+ return result;\r
+}\r
+\r
+/**\r