dataChanged(index,index);
}
+void MDomItemModel::insertNode(const QDomNode& newnode, const QModelIndex& parent, int row)
+{
+ //check parent validity
+ if(!parent.isValid())return;
+ int pid=parent.internalId();
+ if(!d->domCache.contains(pid))return;
+ //only add to tags (TODO: there are a few other node types that can have children)
+ if(!d->domCache[pid].node.isElement())return;
+ //get the parent and a clone of the new node
+ QDomNode nn=newnode.cloneNode();
+ QDomElement pn=d->domCache[pid].node.toElement();
+ const int rcnt=rowCount(parent);
+ //handle appending
+ if(row<0 || row>=rcnt){
+ beginInsertRows(parent,rcnt,rcnt);
+ pn.appendChild(nn);
+ d->domCache[pid].children.append(d->buildCache(nn,pid));
+ endInsertRows();
+ return;
+ }
+ //handle inserting
+ //get current occupant of this row
+ QDomNode sibl=node(index(row,0,parent));
+ beginInsertRows(parent,row,row);
+ //insert
+ pn.insertBefore(nn,sibl);
+ d->domCache[pid].children.insert(row,d->buildCache(nn,pid));
+ endInsertRows();
+}
+
int MDomItemModel::columnCount(const QModelIndex&) const
{
return 1;
else endResetModel();
}
-void MDomItemModel::Private::removeNode(int nid,bool rec)
+void MDomItemModel::Private::removeNode(int nid,bool inrecurs)
{
//sanity check
if(!domCache.contains(nid))return;
//remove main node from model
- if(!rec){
+ if(!inrecurs){
int pid=domCache[nid].parent;
if(domCache.contains(pid)){
domCache[pid].node.removeChild(domCache[nid].node);
+ domCache[pid].children.removeAll(nid);
}
}
//remove children
m->addAction(tr("&Close"),this,SLOT(close()));
QMenu*medit=m=mb->addMenu(tr("&Edit"));
- d->maAddIntoCalc=m->addAction(tr("Insert &Calculation into current"));
- d->maInsBehindCalc=m->addAction(tr("Insert Calculation behind current"));
+ d->maAddIntoCalc=m->addAction(tr("Insert &Calculation into current"),this,SLOT(insCalcIntoCurrent()));
+ d->maInsBehindCalc=m->addAction(tr("Insert Calculation behind current"),this,SLOT(insCalcBehindCurrent()));
d->maWrapInCond=m->addAction(tr("&Wrap in Condition"));
d->maWrapInLoop=m->addAction(tr("Wrap in &Loop"));
- d->maInsBehindElse=m->addAction(tr("Insert &Else behind current"));
- d->maAddIntoComment=m->addAction(tr("Insert Comment into current"));
- d->maInsBehindComment=m->addAction(tr("Insert Comment behind current"));
+ d->maInsBehindElse=m->addAction(tr("Insert &Else behind current"),this,SLOT(insElse()));
+ d->maAddIntoComment=m->addAction(tr("Insert Comment into current"),this,SLOT(insCommentIntoCurrent()));
+ d->maInsBehindComment=m->addAction(tr("Insert Comment behind current"),this,SLOT(insCommentBehindCurrent()));
m->addSeparator();
d->maUnwrap=m->addAction(tr("Unwrap Loop/Condition"));
d->maDelItem=m->addAction(tr("&Remove Item"),this,SLOT(delItem()));
emit switchStack(d->st_loop);
d->mLoopVar->setText(el.attribute("variable"));
d->setActions(QList<QAction*>()<<d->maInsBehindCalc<<d->maInsBehindComment<<d->maAddIntoCalc<<d->maAddIntoComment<<d->maWrapInCond<<d->maWrapInLoop<<d->maUnwrap<<d->maDelItem<<(allowElse?d->maInsBehindElse:nullptr));
- #warning implement correct actions for special tags
return;
}
if(nn[1]=="calculate"){
emit switchStack(d->st_calc);
d->mCalcExpr->setText(el.attribute("exec"));
- d->setActions(QList<QAction*>()<<d->maInsBehindCalc<<d->maInsBehindComment<<d->maAddIntoCalc<<d->maAddIntoComment<<d->maWrapInCond<<d->maWrapInLoop<<d->maDelItem<<(allowElse?d->maInsBehindElse:nullptr));
+ d->setActions(QList<QAction*>()<<d->maInsBehindCalc<<d->maInsBehindComment<<d->maAddIntoComment<<d->maWrapInCond<<d->maWrapInLoop<<d->maDelItem<<(allowElse?d->maInsBehindElse:nullptr));
return;
}
if(nn[1]=="if"){
}
if(nn[1]=="template" || nn[1]=="else"){
emit switchStack(d->st_special);
- d->setActions(QList<QAction*>());
d->mSpecial->setText(tr("<b>Tag Type:</b> %1").arg(htmlize(nn[1])));
+ if(nn[1]=="else"){
+ d->setActions(QList<QAction*>()<<d->maDelItem<<d->maInsBehindCalc<<d->maInsBehindComment);
+ }else
+ d->setActions(QList<QAction*>());
return;
}
//else: fall through to normal tags
maUnwrap->setEnabled(act.contains(maUnwrap));
maDelItem->setEnabled(act.contains(maDelItem));
}
+
+void MOdfEditor::insCalcBehindCurrent()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ QDomNode cnode=d->mDomModel->node(idx);
+ if(cnode.isNull())return;
+ //insert calculation
+ QDomNode nn=cnode.ownerDocument().createElement(OdfTemplatePrefix+":calculate");
+ d->mDomModel->insertNode(nn,idx.parent(),idx.row()+1);
+}
+
+void MOdfEditor::insCalcIntoCurrent()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ QDomNode cnode=d->mDomModel->node(idx);
+ if(cnode.isNull())return;
+ //insert calculation
+ QDomNode nn=cnode.ownerDocument().createElement(OdfTemplatePrefix+":calculate");
+ d->mDomModel->insertNode(nn,idx,0);
+}
+
+void MOdfEditor::insElse()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ QDomNode cnode=d->mDomModel->node(idx);
+ if(cnode.isNull())return;
+ //check parent
+ QDomElement pnode=d->mDomModel->node(idx.parent()).toElement();
+ if(pnode.isNull() || pnode.tagName()!= (OdfTemplatePrefix+":if")){
+ qDebug()<<"oops. trying to insert an else into a parent that is not an if";
+ return;
+ }
+ //insert else tag
+ QDomNode nn=cnode.ownerDocument().createElement(OdfTemplatePrefix+":else");
+ d->mDomModel->insertNode(nn,idx.parent(),idx.row()+1);
+}
+
+void MOdfEditor::delItem()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ //delete
+ d->mDomModel->removeNode(idx);
+}
+
+void MOdfEditor::insCommentBehindCurrent()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ QDomNode cnode=d->mDomModel->node(idx);
+ if(cnode.isNull())return;
+ //insert comment
+ QDomNode nn=cnode.ownerDocument().createComment(tr("new comment"));
+ d->mDomModel->insertNode(nn,idx.parent(),idx.row()+1);
+}
+
+void MOdfEditor::insCommentIntoCurrent()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ QDomNode cnode=d->mDomModel->node(idx);
+ if(cnode.isNull())return;
+ //insert comment
+ QDomNode nn=cnode.ownerDocument().createComment(tr("new comment"));
+ d->mDomModel->insertNode(nn,idx,0);
+}