expandtree

This commit is contained in:
mrbesen 2021-12-25 14:37:34 +01:00
parent e4cd81e811
commit 018ff05990
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 16 additions and 16 deletions

View File

@ -39,6 +39,7 @@ public:
T* getItemBelow() const; T* getItemBelow() const;
void reenumerateAllSiblings(); void reenumerateAllSiblings();
void expandTree(); // expand this and every parent item
protected: protected:
QTreeWidgetItem* mparent = nullptr; QTreeWidgetItem* mparent = nullptr;
uint8_t pos = 0; uint8_t pos = 0;

View File

@ -91,6 +91,14 @@ void ButtonManagerItem::reenumerateAllSiblings() {
} }
} }
void ButtonManagerItem::expandTree() {
ButtonManagerItem* c = this;
while(c) {
c->setExpanded(true);
c = c->getParent<ButtonManagerItem>();
}
}
void ButtonManagerItem::updateAllPosBellow(int8_t diff, uint8_t size) { void ButtonManagerItem::updateAllPosBellow(int8_t diff, uint8_t size) {
for(uint8_t i = pos+1; i < size; ++i) { for(uint8_t i = pos+1; i < size; ++i) {
ButtonManagerItem* item = getSibling<ButtonManagerItem>(i); ButtonManagerItem* item = getSibling<ButtonManagerItem>(i);
@ -149,11 +157,10 @@ void RowItem::moveUp() {
Log::error << "row above could not be updated"; Log::error << "row above could not be updated";
} }
bool wasexpanded = isExpanded();
mparent->removeChild(this); mparent->removeChild(this);
mparent->insertChild(pos-1, this); mparent->insertChild(pos-1, this);
setExpanded(wasexpanded); expandTree();
pos--; pos--;
updatePosition(); updatePosition();
@ -233,11 +240,10 @@ void ButtonItem::moveUp() {
Log::error << "button above could not be updated"; Log::error << "button above could not be updated";
} }
bool wasexpanded = isExpanded();
mparent->removeChild(this); mparent->removeChild(this);
mparent->insertChild(pos-1, this); mparent->insertChild(pos-1, this);
setExpanded(wasexpanded); expandTree();
pos--; pos--;
} }
@ -285,7 +291,6 @@ void ButtonItem::moveToRowAbove() {
// updateAllPosBellow(-1, rowconf.size()+1); // updateAllPosBellow(-1, rowconf.size()+1);
// remove button from this row and attach to other // remove button from this row and attach to other
bool wasExpanded = isExpanded();
getParent<RowItem>()->removeChild(this); getParent<RowItem>()->removeChild(this);
reenumerateAllSiblings(); // depends on mparent beeing set to the old row reenumerateAllSiblings(); // depends on mparent beeing set to the old row
@ -297,7 +302,7 @@ void ButtonItem::moveToRowAbove() {
//update local pos //update local pos
pos = newrowconf.size()-1; pos = newrowconf.size()-1;
setExpanded(wasExpanded); expandTree();
} }
void ButtonItem::moveToRowBelow() { void ButtonItem::moveToRowBelow() {
@ -316,7 +321,6 @@ void ButtonItem::moveToRowBelow() {
rowconf.erase(rowconf.end()); rowconf.erase(rowconf.end());
// remove button from this row and attach to other // remove button from this row and attach to other
bool wasExpanded = isExpanded();
getParent<RowItem>()->removeChild(this); getParent<RowItem>()->removeChild(this);
rowbelow->insertChild(0, this); rowbelow->insertChild(0, this);
@ -329,7 +333,7 @@ void ButtonItem::moveToRowBelow() {
//update new buttons below //update new buttons below
updateAllPosBellow(1, newrowconf.size()); updateAllPosBellow(1, newrowconf.size());
setExpanded(wasExpanded); expandTree();
} }
@ -400,11 +404,10 @@ void SampleItem::moveUp() {
Log::error << "button above could not be updated"; Log::error << "button above could not be updated";
} }
bool wasexpanded = isExpanded();
mparent->removeChild(this); mparent->removeChild(this);
mparent->insertChild(pos-1, this); mparent->insertChild(pos-1, this);
setExpanded(wasexpanded); expandTree();
pos--; pos--;
updatePosition(); updatePosition();
@ -450,7 +453,6 @@ void SampleItem::moveToButtonAbove() {
// updateAllPosBellow(-1, rowconf.size()+1); // updateAllPosBellow(-1, rowconf.size()+1);
// remove button from this row and attach to other // remove button from this row and attach to other
bool wasExpanded = isExpanded();
getParent<ButtonItem>()->removeChild(this); getParent<ButtonItem>()->removeChild(this);
reenumerateAllSiblings(); // depends on mparent beeing set to the old row reenumerateAllSiblings(); // depends on mparent beeing set to the old row
@ -462,8 +464,7 @@ void SampleItem::moveToButtonAbove() {
//update local pos //update local pos
pos = newbuttonconf.size()-1; pos = newbuttonconf.size()-1;
setExpanded(wasExpanded); expandTree();
mparent->setExpanded(true);
updatePosition(); updatePosition();
} }
@ -482,7 +483,6 @@ void SampleItem::moveToButtonBelow() {
buttonConf.erase(buttonConf.end()); buttonConf.erase(buttonConf.end());
// remove button from this row and attach to other // remove button from this row and attach to other
bool wasExpanded = isExpanded();
getParent<ButtonItem>()->removeChild(this); getParent<ButtonItem>()->removeChild(this);
buttonbelow->insertChild(0, this); buttonbelow->insertChild(0, this);
@ -495,6 +495,5 @@ void SampleItem::moveToButtonBelow() {
//update new buttons below //update new buttons below
reenumerateAllSiblings(); reenumerateAllSiblings();
setExpanded(wasExpanded); expandTree();
mparent->setExpanded(true);
} }