2013-09-18 21:16:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Valentina project All Rights Reserved.
|
|
|
|
**
|
|
|
|
** This file is part of Valentina.
|
|
|
|
**
|
|
|
|
** Tox is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-10 14:29:06 +02:00
|
|
|
#ifndef VMODELINGTOOL_H
|
|
|
|
#define VMODELINGTOOL_H
|
|
|
|
|
|
|
|
#include "../vabstracttool.h"
|
|
|
|
#include <QMenu>
|
|
|
|
|
2013-10-27 12:56:05 +01:00
|
|
|
class VModelingTool: public VAbstractTool{
|
2013-09-10 14:29:06 +02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-10-27 12:56:05 +01:00
|
|
|
VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
|
|
|
|
virtual ~VModelingTool(){}
|
|
|
|
virtual void setDialog(){}
|
|
|
|
inline void ignoreContextMenu(bool enable) {ignoreContextMenuEvent = enable;}
|
2013-09-10 14:29:06 +02:00
|
|
|
public slots:
|
|
|
|
virtual void FullUpdateFromGui(int result)=0;
|
2013-09-30 18:29:03 +02:00
|
|
|
signals:
|
|
|
|
void RemoveTool(QGraphicsItem *tool);
|
2013-09-10 14:29:06 +02:00
|
|
|
protected:
|
|
|
|
bool ignoreContextMenuEvent;
|
2013-10-18 12:03:01 +02:00
|
|
|
bool ignoreFullUpdate;
|
2013-09-10 14:29:06 +02:00
|
|
|
void AddToModeling(const QDomElement &domElement);
|
2013-09-30 18:29:03 +02:00
|
|
|
virtual void decrementReferens();
|
2013-09-10 14:29:06 +02:00
|
|
|
template <typename Dialog, typename Tool>
|
|
|
|
void ContextMenu(QSharedPointer<Dialog> &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event,
|
|
|
|
bool showRemove = true){
|
|
|
|
if(!ignoreContextMenuEvent){
|
|
|
|
QMenu menu;
|
2013-10-18 12:03:01 +02:00
|
|
|
QAction *actionOption = menu.addAction(tr("Option"));
|
|
|
|
QAction *actionRemove = 0;
|
2013-09-10 14:29:06 +02:00
|
|
|
if(showRemove){
|
2013-10-18 12:03:01 +02:00
|
|
|
actionRemove = menu.addAction(tr("Delete"));
|
2013-10-18 12:43:51 +02:00
|
|
|
if(_referens > 1){
|
|
|
|
actionRemove->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
actionRemove->setEnabled(true);
|
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
|
|
|
QAction *selectedAction = menu.exec(event->screenPos());
|
|
|
|
if(selectedAction == actionOption){
|
2013-10-18 12:03:01 +02:00
|
|
|
dialog = QSharedPointer<Dialog>(new Dialog(getData()));
|
2013-09-10 14:29:06 +02:00
|
|
|
|
2013-10-18 12:03:01 +02:00
|
|
|
connect(qobject_cast< VMainGraphicsScene * >(tool->scene()),
|
|
|
|
&VMainGraphicsScene::ChoosedObject, dialog.data(), &Dialog::ChoosedObject);
|
|
|
|
connect(dialog.data(), &Dialog::DialogClosed, tool, &Tool::FullUpdateFromGui);
|
|
|
|
if(!ignoreFullUpdate){
|
|
|
|
connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList);
|
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
|
|
|
|
tool->setDialog();
|
|
|
|
|
|
|
|
dialog->show();
|
|
|
|
}
|
2013-10-18 12:03:01 +02:00
|
|
|
if(showRemove){
|
|
|
|
if(selectedAction == actionRemove){
|
|
|
|
//deincrement referens
|
|
|
|
RemoveReferens();
|
|
|
|
//remove form xml file
|
|
|
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
|
|
|
if(domElement.isElement()){
|
|
|
|
QDomElement element;
|
|
|
|
bool ok = doc->GetActivCalculationElement(element);
|
|
|
|
if(ok){
|
|
|
|
element.removeChild(domElement);
|
|
|
|
//update xml file
|
|
|
|
emit FullUpdateTree();
|
|
|
|
//remove form scene
|
|
|
|
emit RemoveTool(tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-10 14:29:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VMODELINGTOOL_H
|