From ae162a6632ffd6e99778bcafb61011c67b23b346 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Sun, 10 Jul 2016 15:49:12 +0200 Subject: [PATCH] fix template add function --- src/templates/templatedlg.cpp | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/templates/templatedlg.cpp b/src/templates/templatedlg.cpp index 00680df..4adb811 100644 --- a/src/templates/templatedlg.cpp +++ b/src/templates/templatedlg.cpp @@ -141,7 +141,7 @@ void MTemplateEditor::updateView() QModelIndex idx=model->index(i,0); model->setData(idx,base[i]); model->setData(idx,base[i],BASEROLE); - model->setData(idx,"",NAMEROLE); + model->setData(idx,"",NAMEROLE);//base must contain empty name for logic in deleteItem and addItem model->itemFromIndex(idx)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); model->setData(model->index(i,1),""); model->itemFromIndex(model->index(i,1))->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); @@ -193,9 +193,10 @@ void MTemplateEditor::addItem() //get selection QModelIndex idx=tree->currentIndex(); if(!idx.isValid())return; - QModelIndex pidx=idx.parent(); - QModelIndex bidx=model->index(idx.row(),0,pidx); - QString base=model->data(bidx,BASEROLE).toString(); + //parent index is the one with the base (top level), bidx is the first one below + QModelIndex pidx=model->data(idx,NAMEROLE).toString().trimmed().isEmpty()?idx:idx.parent(); + QString base=model->data(idx,BASEROLE).toString(); +// qDebug()<<"base"<data(idx,NAMEROLE).toString()<<(pidx.isValid()?"v":"nv"); if(base=="")return; //query file name QString fn=QFileDialog::getOpenFileName(this,tr("Select Template File"),currentDir()); -- 1.7.2.5