fix template add function
authorKonrad Rosenbaum <konrad@silmor.de>
Sun, 10 Jul 2016 13:49:12 +0000 (15:49 +0200)
committerKonrad Rosenbaum <konrad@silmor.de>
Sun, 10 Jul 2016 13:49:12 +0000 (15:49 +0200)
src/templates/templatedlg.cpp

index 00680df..4adb811 100644 (file)
@@ -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"<<base<<"name"<<model->data(idx,NAMEROLE).toString()<<(pidx.isValid()?"v":"nv");
        if(base=="")return;
        //query file name
        QString fn=QFileDialog::getOpenFileName(this,tr("Select Template File"),currentDir());