#include "odtrender.h"
#include "dommodel.h"
#include "cleanup.h"
+#include "domiterator.h"
#include "orderwin.h"
#include "eventsummary.h"
//tree menu
QAction*maAddIntoCalc,*maWrapInCond,*maAddIntoComment;
QAction*maInsBehindElse,*maWrapInLoop;
- QAction*maInsBehindCalc,*maInsBehindComment,*maUnwrap,*maDelItem;
- void setActions(const QList<QAction*>&);
+ QAction*maInsBehindCalc,*maInsBehindComment,*maUnwrap;
+ QAction*maInsItemInto,*maInsItemBehind,*maCpyItem,*maDelItem;
+ void setActions(const QList<QAction*>&,bool haveselect=true);
//current node
QModelIndex mCurIndex;
- QDomNode mCurNode;
+ QDomNode mCurNode,mClipNode;
bool mChanged;
//test printing
QString mTestFile;
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->maCpyItem=m->addAction(tr("Copy current item to clipboard"),this,SLOT(copyItem()));
+ d->maInsItemInto=m->addAction(tr("Insert clipboard into current"),this,SLOT(pasteItemInto()));
+ d->maInsItemBehind=m->addAction(tr("Insert clipboard behind current"),this,SLOT(pasteItemBehind()));
m->addSeparator();
d->maUnwrap=m->addAction(tr("Unwrap Loop/Condition"),this,SLOT(unwrapItem()));
d->maDelItem=m->addAction(tr("&Remove Item"),this,SLOT(delItem()));
void MOdfEditor::openFile(bool istemp)
{
+ d->mClipNode.clear();
QString title=istemp?tr("Open ODF Template"):tr("Open ODF File");
QString flt=istemp?tr("ODF Template File (*.od?t);;All Files (*)"):tr("ODF File (*.od?);;All Files (*)");
QString fn=QFileDialog::getOpenFileName(this,title,currentDir(),flt);
MCleanup clean([&](){setChanged(false);});
d->mCurIndex=QModelIndex();
d->mCurNode=QDomNode();
- d->setActions(QList<QAction*>());
+ d->setActions(QList<QAction*>(),false);
//get selection
QModelIndexList idxl=d->mDomTree->selectionModel()->selectedRows();
if(idxl.size()!=1){
emit switchStack(d->st_none);
if(idxl.size()>1)
- d->setActions(QList<QAction*>()<<d->maWrapInCond<<d->maWrapInLoop);
+ d->setActions(QList<QAction*>()<<d->maWrapInCond<<d->maWrapInLoop,false);
return;
}
//check element type
// qDebug()<<"done saving";
}
-void MOdfEditor::Private::setActions(const QList< QAction* >& act)
+void MOdfEditor::Private::setActions(const QList< QAction* >& act,bool haveselect)
{
maAddIntoCalc->setEnabled(act.contains( maAddIntoCalc));
maWrapInCond->setEnabled(act.contains( maWrapInCond));
maInsBehindComment->setEnabled(act.contains( maInsBehindComment));
maUnwrap->setEnabled(act.contains(maUnwrap));
maDelItem->setEnabled(act.contains(maDelItem));
+ maCpyItem->setEnabled(haveselect);
+ maInsItemBehind->setEnabled(haveselect && !mClipNode.isNull());
+ maInsItemInto->setEnabled(haveselect && !mClipNode.isNull());
}
void MOdfEditor::insCalcBehindCurrent()
if(lrow<0)frow=lrow=idx.row();
if(lrow<idx.row())lrow=idx.row();
if(frow>idx.row())frow=idx.row();
- ndlist<<d->mDomModel->node(idx);
+ ndlist<<d->mDomModel->node(idx).cloneNode(true);
}
if(ndlist.size()<1)return;
//create new parent node
QModelIndex idx=d->mDomTree->currentIndex();
if(!idx.isValid())return;
//get the node and parent index
- QDomElement el=d->mDomModel->node(idx).toElement();
+ QDomElement el=d->mDomModel->node(idx).cloneNode(true).toElement();
QModelIndex pidx=idx.parent();
const int row=idx.row();
//remove the original
//expand the tree
d->expandTree(pidx);
}
+
+void MOdfEditor::pasteItemBehind()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ QDomNode cnode=d->mDomModel->node(idx);
+ if(cnode.isNull())return;
+ //check
+ if(d->mClipNode.isNull()){
+ QMessageBox::warning(this,tr("Warning"),tr("There is nothing in the clipboard. Please copy a node first."));
+ return;
+ }
+ //insert item
+ d->mDomModel->insertNode(d->mClipNode,idx.parent(),idx.row()+1);
+}
+
+void MOdfEditor::pasteItemInto()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ QDomNode cnode=d->mDomModel->node(idx);
+ if(cnode.isNull())return;
+ //check
+ if(d->mClipNode.isNull()){
+ QMessageBox::warning(this,tr("Warning"),tr("There is nothing in the clipboard. Please copy a node first."));
+ return;
+ }
+ //insert item
+ d->mDomModel->insertNode(d->mClipNode,idx,0);
+ //make sure it is visible
+ d->expandTree(idx);
+}
+
+static inline
+QDomNode xclonenode(const QDomNode&node)
+{
+ if(node.isNull())return QDomNode();
+ QDomDocument doc=node.ownerDocument();
+ QDomNode nn;
+ switch(node.nodeType()){
+ case QDomNode::ElementNode:
+ nn=doc.createElement(node.nodeName());
+ for(const QDomNode&ond:node.childNodes())
+ nn.appendChild(xclonenode(ond));
+ break;
+ case QDomNode::AttributeNode:
+ nn=doc.createAttribute(node.nodeName());
+ nn.setNodeValue(node.nodeValue());
+ break;
+ case QDomNode::TextNode:
+ nn=doc.createTextNode(node.nodeValue());
+ break;
+ case QDomNode::CharacterDataNode:
+ case QDomNode::CDATASectionNode:
+ nn=doc.createCDATASection(node.nodeValue());
+ break;
+ case QDomNode::ProcessingInstructionNode:
+ nn=doc.createProcessingInstruction(node.nodeName(),node.nodeValue());
+ break;
+ case QDomNode::CommentNode:
+ nn=doc.createComment(node.nodeValue());
+ break;
+ //those are currently not supported or it is completely useless to copy them
+ case QDomNode::EntityReferenceNode:
+ case QDomNode::EntityNode:
+ case QDomNode::DocumentNode:
+ case QDomNode::DocumentTypeNode:
+ case QDomNode::DocumentFragmentNode:
+ case QDomNode::NotationNode:
+ case QDomNode::BaseNode:
+ return QDomNode();
+ }
+ return nn;
+}
+
+void MOdfEditor::copyItem()
+{
+ //get current
+ QModelIndex idx=d->mDomTree->currentIndex();
+ if(!idx.isValid())return;
+ QDomNode cnode=d->mDomModel->node(idx);
+ if(cnode.isNull())return;
+ //remember
+ if(!d->mClipNode.isNull())d->mClipNode.clear();
+ d->mClipNode=cnode.cloneNode(true);
+ //housekeeping
+ d->maInsItemBehind->setEnabled(!d->mClipNode.isNull());
+ d->maInsItemInto->setEnabled(!d->mClipNode.isNull());
+ if(d->mClipNode.isNull())
+ QMessageBox::warning(this,tr("Warning"),tr("Sorry, this kinde of node cannot be copied."));
+}