@@ -64,6 +64,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
6464 connect (ui->ControlPointColorButton , &QToolButton::clicked, this , &lcQPreferencesDialog::ColorButtonClicked);
6565 connect (ui->ControlPointFocusedColorButton , &QToolButton::clicked, this , &lcQPreferencesDialog::ColorButtonClicked);
6666 connect (ui->categoriesTree , &QTreeWidget::itemSelectionChanged, this , &lcQPreferencesDialog::updateParts);
67+ connect (ui->categoriesTree ->model (), &QAbstractItemModel::rowsInserted, this , &lcQPreferencesDialog::CategoriesDropped);
6768 ui->shortcutEdit ->installEventFilter (this );
6869 connect (ui->commandList , &QTreeWidget::currentItemChanged, this , &lcQPreferencesDialog::commandChanged);
6970 connect (ui->mouseTree , &QTreeWidget::currentItemChanged, this , &lcQPreferencesDialog::MouseTreeItemChanged);
@@ -689,17 +690,20 @@ void lcQPreferencesDialog::updateCategories()
689690{
690691 QTreeWidgetItem* CategoryItem;
691692 QTreeWidget* CategoriesTree = ui->categoriesTree ;
693+ QSignalBlocker Blocker (CategoriesTree->model ());
692694
693695 CategoriesTree->clear ();
694696
695697 for (int CategoryIndex = 0 ; CategoryIndex < static_cast <int >(mOptions ->Categories .size ()); CategoryIndex++)
696698 {
697699 CategoryItem = new QTreeWidgetItem (CategoriesTree, QStringList (mOptions ->Categories [CategoryIndex].Name ));
698700 CategoryItem->setData (0 , CategoryRole, QVariant (CategoryIndex));
701+ CategoryItem->setFlags (CategoryItem->flags () & ~Qt::ItemFlag::ItemIsDropEnabled);
699702 }
700703
701704 CategoryItem = new QTreeWidgetItem (CategoriesTree, QStringList (tr (" Unassigned" )));
702705 CategoryItem->setData (0 , CategoryRole, QVariant (-1 ));
706+ CategoryItem->setFlags (CategoryItem->flags () & ~Qt::ItemFlag::ItemIsDropEnabled);
703707}
704708
705709void lcQPreferencesDialog::updateParts ()
@@ -757,6 +761,27 @@ void lcQPreferencesDialog::updateParts()
757761 tree->resizeColumnToContents (1 );
758762}
759763
764+ void lcQPreferencesDialog::CategoriesDropped (const QModelIndex& Parent, int First, int Last)
765+ {
766+ std::vector<lcLibraryCategory> Categories;
767+
768+ for (int Row = 0 ; Row < ui->categoriesTree ->topLevelItemCount (); Row++)
769+ {
770+ QTreeWidgetItem* CategoryItem = ui->categoriesTree ->topLevelItem (Row);
771+ size_t CategoryIndex = CategoryItem->data (0 , CategoryRole).toInt ();
772+
773+ if (CategoryIndex >= 0 && CategoryIndex < mOptions ->Categories .size ())
774+ {
775+ Categories.emplace_back (mOptions ->Categories [CategoryIndex]);
776+ CategoryItem->setData (0 , CategoryRole, Row);
777+ }
778+ }
779+
780+ mOptions ->CategoriesModified = true ;
781+ mOptions ->CategoriesDefault = false ;
782+ mOptions ->Categories = std::move (Categories);
783+ }
784+
760785void lcQPreferencesDialog::on_newCategory_clicked ()
761786{
762787 lcLibraryCategory category;
0 commit comments