void ItemBoxTreeWidget::slotScratchPadItemDeleted() { const int scratch_idx = indexOfScratchpad(); QTreeWidgetItem *scratch_item = topLevelItem(scratch_idx); adjustSubListSize(scratch_item); // save(); }
void ItemBoxTreeWidget::deleteScratchpad() { const int idx = indexOfScratchpad(); if (idx == -1) { return; } delete takeTopLevelItem(idx); //save(); }
int WidgetBoxTreeWidget::ensureScratchpad() { const int existingIndex = indexOfScratchpad(); if (existingIndex != -1) return existingIndex; QTreeWidgetItem *scratch_item = new QTreeWidgetItem(this); scratch_item->setText(0, tr("Scratchpad")); setTopLevelRole(SCRATCHPAD_ITEM, scratch_item); addCategoryView(scratch_item, false); // Scratchpad in list mode. return categoryCount() - 1; }
void ItemBoxTreeWidget::addCategory(const Category &cat, int index) { // if (cat.itemCount() == 0) // return; const bool isScratchPad = cat.type() == Category::Scratchpad; ItemBoxCategoryListView *categoryView = 0; QTreeWidgetItem *cat_item = 0; if (isScratchPad) { const int idx = ensureScratchpad(); categoryView = categoryViewAt(idx); cat_item = topLevelItem(idx); } else { const int existingIndex = indexOfCategory(cat.id()); if (existingIndex == -1) { cat_item = new QTreeWidgetItem(); cat_item->setData(0, Qt::UserRole, QVariant(cat.id())); cat_item->setText(0, cat.name()); setTopLevelRole(NORMAL_ITEM, cat_item); // insert before scratchpad const int scratchPadIndex = indexOfScratchpad(); if (scratchPadIndex == -1) { if(index == -1) { addTopLevelItem(cat_item); } else { insertTopLevelItem(index, cat_item); } } else { insertTopLevelItem(scratchPadIndex, cat_item); } setItemExpanded(cat_item, true); categoryView = addCategoryView(cat_item, m_iconMode); } else { categoryView = categoryViewAt(existingIndex); cat_item = topLevelItem(existingIndex); } } // The same categories are read from the file $HOME, avoid duplicates const int widgetCount = cat.itemCount(); for (int i = 0; i < widgetCount; ++i) { const Item w = cat.item(i); if (!categoryView->containsItem(w.name())) { categoryView->addItem(w, w.icon(), isScratchPad); } } adjustSubListSize(cat_item); }