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);
//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());