From: Konrad Rosenbaum Date: Sun, 10 Jul 2016 13:49:12 +0000 (+0200) Subject: fix template add function X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=ae162a6632ffd6e99778bcafb61011c67b23b346;p=web%2Fkonrad%2Fsmoke.git fix template add function --- 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());