Core: Tree: Allow reordering in root and groups allowing it (parts, groups

This commit is contained in:
PaddleStroke
2024-02-13 09:53:31 +01:00
committed by Chris Hennes
parent cc5d4146cf
commit fec1a86e30
8 changed files with 1038 additions and 746 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -140,6 +140,18 @@ protected:
void dragLeaveEvent(QDragLeaveEvent * event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
void dropEvent(QDropEvent *event) override;
struct TargetItemInfo {
QTreeWidgetItem* targetItem = nullptr; //target may be the parent of underMouse
QTreeWidgetItem* underMouseItem = nullptr;
App::Document* targetDoc = nullptr;
QPoint pos;
bool inBottomHalf = false;
bool inThresholdZone = false;
};
TargetItemInfo getTargetInfo(QEvent* ev);
bool dropInObject(QDropEvent* event, TargetItemInfo& targetInfo, std::vector<std::pair<DocumentObjectItem*, std::vector<std::string> > > items);
bool dropInDocument(QDropEvent* event, TargetItemInfo& targetInfo, std::vector<std::pair<DocumentObjectItem*, std::vector<std::string> > > items);
void sortDroppedObjects(TargetItemInfo& targetInfo, std::vector<App::DocumentObject*> draggedObjects);
//@}
bool event(QEvent *e) override;
void keyPressEvent(QKeyEvent *event) override;
@@ -291,6 +303,7 @@ public:
void setData(int column, int role, const QVariant & value) override;
void populateItem(DocumentObjectItem *item, bool refresh=false, bool delayUpdate=true);
bool populateObject(App::DocumentObject *obj);
void sortObjectItems();
void selectAllInstances(const ViewProviderDocumentObject &vpd);
bool showItem(DocumentObjectItem *item, bool select, bool force=false);
void updateItemsVisibility(QTreeWidgetItem *item, bool show);
@@ -439,10 +452,14 @@ public:
int isParentGroup() const;
DocumentObjectItem *getParentItem() const;
DocumentObjectItem *getNextSibling() const;
DocumentObjectItem *getPreviousSibling() const;
TreeWidget *getTree() const;
private:
void setCheckState(bool checked);
void getExpandedSnapshot(std::vector<bool>& snapshot) const;
void applyExpandedSnapshot(const std::vector<bool>& snapshot, std::vector<bool>::const_iterator& from);
QBrush bgBrush;
DocumentItem *myOwner;

View File

@@ -310,6 +310,8 @@ public:
* */
virtual bool canDropObjectEx(App::DocumentObject *obj, App::DocumentObject *owner,
const char *subname, const std::vector<std::string> &elements) const;
/* Check whether the object accept reordering of its children during drop.*/
virtual bool acceptReorderingObjects() const { return false; };
/// return a subname referencing the sub-object holding the dropped objects
virtual std::string getDropPrefix() const { return {}; }

View File

@@ -77,6 +77,8 @@ ViewProviderDocumentObject::ViewProviderDocumentObject()
"Element: On top only if some sub-element of the object is selected");
OnTopWhenSelected.setEnums(OnTopEnum);
ADD_PROPERTY_TYPE(TreeRank, (-1), dogroup, App::Prop_Hidden, "Tree view item ordering key");
sPixmap = "Feature";
}

View File

@@ -64,6 +64,9 @@ public:
App::PropertyEnumeration OnTopWhenSelected;
App::PropertyEnumeration SelectionStyle;
// Hidden properties
App::PropertyInteger TreeRank;
virtual void attach(App::DocumentObject *pcObject);
virtual void reattach(App::DocumentObject *);
void update(const App::Property*) override;

View File

@@ -48,6 +48,9 @@ public:
/// deliver the icon shown in the tree view
QIcon getIcon() const override;
/* Check whether the object accept reordering of its children during drop.*/
bool acceptReorderingObjects() const override { return true; };
protected:
void getViewProviders(std::vector<ViewProviderDocumentObject*>&) const;

View File

@@ -80,8 +80,8 @@ bool ViewProviderGroupExtension::extensionCanDropObject(App::DocumentObject* obj
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
//we cannot drop thing of this group into it again
if (group->hasObject(obj))
//we cannot drop thing of this group into it again if it does not allow reorder
if (group->hasObject(obj) && !getExtendedViewProvider()->acceptReorderingObjects())
return false;
if (group->allowObject(obj))

View File

@@ -50,6 +50,9 @@ public:
/// override from ViewProvider.h
QIcon getIcon() const override;
/* Check whether the object accept reordering of its children during drop.*/
bool acceptReorderingObjects() const override { return true; };
protected:
/// get called by the container whenever a property has been changed
void onChanged(const App::Property* prop) override;