From c9e1751c0ad9bb0f140cdf7cf24608cc86836259 Mon Sep 17 00:00:00 2001 From: Arno Date: Thu, 21 Jul 2016 17:24:23 +0200 Subject: Implement add tree in SlideDlg + others Yeah! Finalling getting the hang of recursion, I hope! Add a new Button ">>>>" to add a whole subtree. Not really useful when archiving, but very useful when selecting Slide attributes! --- mappingtreewidget.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'mappingtreewidget.cpp') diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index a0518d1..076f7d6 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -128,6 +128,30 @@ MappingData MappingTreeWidget::selectedItem() const { return mModel->mappingDataFromIndex(real); } +QList MappingTreeWidget::selectedTree() const { + QModelIndex start = selected(); + QList retval; + retval << selectedTreeRecursive(start); + return retval; +} + +QList MappingTreeWidget::selectedTreeRecursive(const QModelIndex &start) const{ + QList retval; + QModelIndex curChild = start.child(0,0); + if(!curChild.isValid()){ + QModelIndex real = mProxy->mapToSource(start); + retval << mModel->mappingDataFromIndex(real); + return retval; + } + int row = 0; + while(curChild.isValid()){ + retval << selectedTreeRecursive(curChild); + ++row; + curChild = start.child(row, 0); + } + return retval; +} + void MappingTreeWidget::addChild(){ MappingInputDialog dlg(this); int retval = dlg.exec(); @@ -367,6 +391,8 @@ MappingEditWidget::MappingEditWidget(QWidget *parent) : QWidget(parent){ connect(mRemoveMapping, SIGNAL(clicked()), this, SLOT(removeMapping())); mClearMapping = new QPushButton(tr("&Clear")); connect(mClearMapping, SIGNAL(clicked()), this, SLOT(clearMapping())); + mAddTree = new QPushButton(tr(">>>>")); + connect(mAddTree, SIGNAL(clicked()), this, SLOT(addTree())); //layout QHBoxLayout *mainLayout = new QHBoxLayout; @@ -376,6 +402,7 @@ MappingEditWidget::MappingEditWidget(QWidget *parent) : QWidget(parent){ buttonLayout->addWidget(mAddMapping); buttonLayout->addWidget(mRemoveMapping); buttonLayout->addWidget(mClearMapping); + buttonLayout->addWidget(mAddTree); buttonLayout->addStretch(); mainLayout->addLayout(buttonLayout); mainLayout->addWidget(mMappingResult); @@ -390,6 +417,15 @@ void MappingEditWidget::addMapping(){ mMappingTree->mappingTreeView()->setFocus(); } +void MappingEditWidget::addTree(){ + QList retval = mMappingTree->selectedTree(); + foreach(MappingData md, retval){ + mResultModel->addItem(md); + } + mMappingResult->expandAll(); + mMappingTree->mappingTreeView()->setFocus(); +} + void MappingEditWidget::removeMapping(){ QModelIndexList sel = mMappingResult->selectionModel()->selectedRows(); if(sel.isEmpty()){ -- cgit v1.2.3-70-g09d2