summaryrefslogtreecommitdiffstats
path: root/mappingtreewidget.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-07-21 17:24:23 +0200
committerArno <arno@disconnect.de>2016-07-21 17:24:23 +0200
commitc9e1751c0ad9bb0f140cdf7cf24608cc86836259 (patch)
tree9034e3e602dab695a445078205e3baf738469f0b /mappingtreewidget.cpp
parentb92c026a4bf23ffdf9d797ae8d053e875f13ce4e (diff)
downloadSheMov-c9e1751c0ad9bb0f140cdf7cf24608cc86836259.tar.gz
SheMov-c9e1751c0ad9bb0f140cdf7cf24608cc86836259.tar.bz2
SheMov-c9e1751c0ad9bb0f140cdf7cf24608cc86836259.zip
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!
Diffstat (limited to 'mappingtreewidget.cpp')
-rw-r--r--mappingtreewidget.cpp36
1 files changed, 36 insertions, 0 deletions
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<MappingData> MappingTreeWidget::selectedTree() const {
+ QModelIndex start = selected();
+ QList<MappingData> retval;
+ retval << selectedTreeRecursive(start);
+ return retval;
+}
+
+QList<MappingData> MappingTreeWidget::selectedTreeRecursive(const QModelIndex &start) const{
+ QList<MappingData> 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<MappingData> 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()){