Merge branch 'dxf2elmt'

* dxf2elmt:
  Element editor : improve code
  Element editor : improve code
  Import dxf is managed by undo command
  Add import dxf feature
This commit is contained in:
joshua
2022-07-26 17:04:22 +02:00
29 changed files with 803 additions and 176 deletions

View File

@@ -159,7 +159,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
$$files(sources/print/*.h) \
$$files(sources/TerminalStrip/*.h) \
$$files(sources/TerminalStrip/ui/*.h) \
$$files(sources/TerminalStrip/UndoCommand/*.h)
$$files(sources/TerminalStrip/UndoCommand/*.h) \
$$files(sources/dxf/*.h)
SOURCES += $$files(sources/*.cpp) \
$$files(sources/editor/*.cpp) \
@@ -195,7 +196,8 @@ SOURCES += $$files(sources/*.cpp) \
$$files(sources/print/*.cpp) \
$$files(sources/TerminalStrip/*.cpp) \
$$files(sources/TerminalStrip/ui/*.cpp) \
$$files(sources/TerminalStrip/UndoCommand/*.cpp)
$$files(sources/TerminalStrip/UndoCommand/*.cpp) \
$$files(sources/dxf/*.cpp)
# Needed for use promote QTreeWidget in terminalstripeditor.ui
INCLUDEPATH += sources/TerminalStrip/ui

102
sources/dxf/dxftoelmt.cpp Normal file
View File

@@ -0,0 +1,102 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dxftoelmt.h"
#include "../ui/thirdpartybinaryinstalldialog.h"
#include <QFile>
#include <QProcess>
#include <QMessageBox>
#include <QDir>
/**
* @brief dxftoElmt
* Return the dxf at @a file_path converted to elmt.
* The returned value is a QByteArray, instead of a
* QDomDocument or QString, to let user do what they want with that.
* @param file_path
* @return
*/
QByteArray dxfToElmt(const QString &file_path)
{
if (!dxf2ElmtIsPresent(false)) {
return QByteArray();
}
QProcess process_;
const QString program{dxf2ElmtBinaryPath()};
const QStringList arguments{file_path, QStringLiteral("-v")};
process_.start(program, arguments);
process_.waitForFinished();
const auto byte_array{process_.readAll()};
process_.close();
return byte_array;
}
QString dxf2ElmtDirPath()
{
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
return (QDir::homePath() + QStringLiteral("/Application Data/qet/binary"));
#elif defined(Q_OS_MAC)
return (QDir::homePath() + QStringLiteral("/.qet/binary"));
#else
return (QDir::homePath() + QStringLiteral("/.qet/binary"));
#endif
}
/**
* @brief dxf2ElmtBinaryPath
* @return the path to the dxf2elmt program
*/
QString dxf2ElmtBinaryPath()
{
#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
return dxf2ElmtDirPath() + QStringLiteral("/dxf2elmt.exe");
#elif defined(Q_OS_MAC)
return dxf2ElmtDirPath() + QStringLiteral("/dxf2elmt.app");
#else
return dxf2ElmtDirPath() + QStringLiteral("/dxf2elmt");
#endif
}
/**
* @brief dxf2ElmtIsPresent
* Return true if dxf2elmt is present in the system
* @param install_dialog
* True to display a dialog with the explanations
* of how to install the dxf2elmt program
* if not present in the system.
* @return
*/
bool dxf2ElmtIsPresent(bool install_dialog, QWidget *parent)
{
const bool exist{QFile::exists(dxf2ElmtBinaryPath())};
if (!exist && install_dialog)
{
auto string_{QStringLiteral("L'import dxf nécessite le logiciel dxf2elmt. \n"
"Veuillez télécharger celui-ci en suivant le lien ci dessous et le dézipper dans le dossier d'installation")};
ThirdPartyBinaryInstallDialog dialog_(string_,
QStringLiteral("https://github.com/antonioaja/dxf2elmt/releases"),
dxf2ElmtDirPath(),
parent);
dialog_.exec();
}
return exist;
}

30
sources/dxf/dxftoelmt.h Normal file
View File

@@ -0,0 +1,30 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DXFTOELMT_H
#define DXFTOELMT_H
#include <QByteArray>
class QWidget;
QByteArray dxfToElmt(const QString &file_path);
QString dxf2ElmtDirPath();
QString dxf2ElmtBinaryPath();
bool dxf2ElmtIsPresent(bool install_dialog = true, QWidget *parent = nullptr);
#endif // DXFTOELMT_H

View File

@@ -0,0 +1,84 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "addpartcommand.h"
#include "../elementscene.h"
/**
* @brief AddPartCommand::AddPartCommand
* @param text : text of the undo command
* @param scene : scene where @a part must be added
* @param part : part to add
* @param parent : parent undo command
*/
AddPartCommand::AddPartCommand(const QString &text,
QPointer<ElementScene> scene,
QGraphicsItem *part,
QUndoCommand *parent) :
QUndoCommand{parent},
m_scene{scene},
m_part{part}
{
setText(text);
m_scene->qgiManager().manage(part);
}
/**
* @brief AddPartCommand::~AddPartCommand
*/
AddPartCommand::~AddPartCommand()
{
if (m_scene) {
m_scene->qgiManager().release(m_part.first());
}
}
/**
* @brief AddPartCommand::undo
*/
void AddPartCommand::undo()
{
if (m_scene) {
m_scene->removeItems(m_part);
}
}
/**
* @brief AddPartCommand::redo
*/
void AddPartCommand::redo()
{
if (!m_scene) {
return;
}
if (m_first_redo)
{
auto part_{m_part.first()};
if (!part_->zValue())
{
// the added part has no specific zValue already defined, we put it
// above existing items (but still under terminals)
const auto existing_items = m_scene->zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot);
const auto z_{existing_items.count() ? existing_items.last()->zValue() + 1 : 1};
part_->setZValue(z_);
}
m_scene->clearSelection();
m_first_redo = false;
}
m_scene->addItems(m_part);
}

View File

@@ -0,0 +1,50 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ADDPARTCOMMAND_H
#define ADDPARTCOMMAND_H
#include <QUndoCommand>
#include <QPointer>
class ElementScene;
class QGraphicsItem;
/**
* @brief The AddPartCommand class
* Undo command use to add a graphics part into an element scene.
*/
class AddPartCommand : public QUndoCommand
{
public:
AddPartCommand(const QString &text, QPointer<ElementScene> scene, QGraphicsItem *part, QUndoCommand *parent = nullptr);
~AddPartCommand() override;
private:
AddPartCommand(const AddPartCommand &);
public:
void undo() override;
void redo() override;
private:
QPointer<ElementScene> m_scene;
QVector<QGraphicsItem *> m_part;
bool m_first_redo{true};
};
#endif // ADDPARTCOMMAND_H

View File

@@ -0,0 +1,66 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "deletepartscommand.h"
#include "../elementscene.h"
/**
* @brief DeletePartsCommand::DeletePartsCommand
* @param scene
* @param parts
* @param parent
*/
DeletePartsCommand::DeletePartsCommand(QPointer<ElementScene> scene,
const QVector<QGraphicsItem *> &parts,
QUndoCommand *parent) :
QUndoCommand{parent},
m_scene{scene},
m_parts{parts}
{
setText(QObject::tr("suppression", "undo caption"));
m_scene->qgiManager().manage(parts);
}
/**
* @brief DeletePartsCommand::~DeletePartsCommand
*/
DeletePartsCommand::~DeletePartsCommand()
{
if (m_scene) {
m_scene->qgiManager().release(m_parts);
}
}
/**
* @brief DeletePartsCommand::undo
*/
void DeletePartsCommand::undo()
{
if (m_scene) {
m_scene->addItems(m_parts);
}
}
/**
* @brief DeletePartsCommand::redo
*/
void DeletePartsCommand::redo()
{
if (m_scene) {
m_scene->removeItems(m_parts);
}
}

View File

@@ -0,0 +1,48 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DELETEPARTSCOMMAND_H
#define DELETEPARTSCOMMAND_H
#include <QUndoCommand>
#include <QPointer>
class ElementScene;
class QGraphicsItem;
/**
* @brief The DeletePartsCommand class
* Class used to remove part from an element scene.
*/
class DeletePartsCommand : public QUndoCommand
{
public:
DeletePartsCommand(QPointer<ElementScene> scene, const QVector<QGraphicsItem *> &parts, QUndoCommand *parent = nullptr);
~DeletePartsCommand() override;
private:
DeletePartsCommand(const DeletePartsCommand &);
public:
void undo() override;
void redo() override;
private:
QPointer<ElementScene> m_scene;
QVector<QGraphicsItem *> m_parts;
};
#endif // DELETEPARTSCOMMAND_H

View File

@@ -0,0 +1,67 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "openelmtcommand.h"
#include "../elementscene.h"
#include <QDomDocument>
#include <QObject>
OpenElmtCommand::OpenElmtCommand(const QDomDocument &document,
QPointer<ElementScene> scene,
QUndoCommand *parent) :
QUndoCommand{parent},
m_document{document.cloneNode().toDocument()},
m_scene{scene}
{
setText(QObject::tr("Ouvrir un element"));
}
OpenElmtCommand::~OpenElmtCommand()
{
if (m_scene) {
m_scene->qgiManager().release(m_graphics_item);
}
}
void OpenElmtCommand::undo()
{
m_scene->removeItems(m_graphics_item.toVector());
}
void OpenElmtCommand::redo()
{
if (!m_scene) {
return;
}
if (m_first_redo)
{
m_scene->fromXml(m_document, QPointF(), true, &m_graphics_item);
m_scene->qgiManager().manage(m_graphics_item);
m_first_redo = false;
//m_document is now useless,
//we clear it to use less memory
m_document.clear();
}
else {
m_scene->addItems(m_graphics_item.toVector());
}
m_scene->slot_select(m_graphics_item);
}

View File

@@ -0,0 +1,44 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPENELMTCOMMAND_H
#define OPENELMTCOMMAND_H
#include <QUndoCommand>
#include <QDomDocument>
#include <QPointer>
class ElementScene;
class QGraphicsItem;
class OpenElmtCommand : public QUndoCommand
{
public:
OpenElmtCommand(const QDomDocument &document, QPointer<ElementScene> scene, QUndoCommand *parent = nullptr);
~OpenElmtCommand() override;
virtual void undo() override;
virtual void redo() override;
private:
QDomDocument m_document;
bool m_first_redo{true};
QPointer<ElementScene> m_scene;
QList<QGraphicsItem *> m_graphics_item;
};
#endif // OPENELMTCOMMAND_H

View File

@@ -90,54 +90,6 @@ void ElementEditionCommand::setElementView(ElementView *view) {
m_view = view;
}
/*** DeletePartsCommand ***/
/**
Constructeur
@param scene ElementScene concernee
@param parts Liste des parties supprimees
@param parent QUndoCommand parent
*/
DeletePartsCommand::DeletePartsCommand(
ElementScene *scene,
const QList<QGraphicsItem *>& parts,
QUndoCommand *parent
) :
ElementEditionCommand(QObject::tr("suppression", "undo caption"), scene, nullptr, parent),
deleted_parts(parts)
{
foreach(QGraphicsItem *qgi, deleted_parts) {
m_scene -> qgiManager().manage(qgi);
}
}
/// Destructeur : detruit egalement les parties supprimees
DeletePartsCommand::~DeletePartsCommand()
{
foreach(QGraphicsItem *qgi, deleted_parts) {
m_scene -> qgiManager().release(qgi);
}
}
/// Restaure les parties supprimees
void DeletePartsCommand::undo()
{
m_scene -> blockSignals(true);
foreach(QGraphicsItem *qgi, deleted_parts) {
m_scene -> addItem(qgi);
}
m_scene -> blockSignals(false);
}
/// Supprime les parties
void DeletePartsCommand::redo()
{
m_scene -> blockSignals(true);
foreach(QGraphicsItem *qgi, deleted_parts) {
m_scene -> removeItem(qgi);
}
m_scene -> blockSignals(false);
}
/*** CutPartsCommand ***/
/**
Constructeur
@@ -150,7 +102,7 @@ CutPartsCommand::CutPartsCommand(
const QList<QGraphicsItem *>& parts,
QUndoCommand *parent
) :
DeletePartsCommand(scene, parts, parent)
DeletePartsCommand(scene, parts.toVector(), parent)
{
setText(QString(QObject::tr("couper des parties", "undo caption")));
}
@@ -203,58 +155,6 @@ void MovePartsCommand::redo()
foreach(QGraphicsItem *qgi, moved_parts) qgi -> moveBy(movement.x(), movement.y());
}
/*** AddPartCommand ***/
/**
Constructeur
@param name Nom de la partie ajoutee
@param scene ElementScene concernee
@param p partie ajoutee
@param parent QUndoCommand parent
*/
AddPartCommand::AddPartCommand(
const QString &name,
ElementScene *scene,
QGraphicsItem *p,
QUndoCommand *parent
) :
ElementEditionCommand(QString(QObject::tr("ajout %1", "undo caption")).arg(name), scene, nullptr, parent),
part(p),
first_redo(true)
{
m_scene -> qgiManager().manage(part);
}
/// Destructeur
AddPartCommand::~AddPartCommand()
{
m_scene -> qgiManager().release(part);
}
/// Annule l'ajout
void AddPartCommand::undo()
{
m_scene -> removeItem(part);
}
/// Refait l'ajout
void AddPartCommand::redo()
{
// le premier appel a redo, lors de la construction de l'objet, ne doit pas se faire
if (first_redo) {
if (!part -> zValue()) {
// the added part has no specific zValue already defined, we put it
// above existing items (but still under terminals)
QList<QGraphicsItem *> existing_items = m_scene -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot);
qreal z = existing_items.count() ? existing_items.last() -> zValue() + 1 : 1;
part -> setZValue(z);
}
m_scene -> clearSelection();
first_redo = false;
return;
}
m_scene -> addItem(part);
}
/**
Constructeur
@param element_scene Element edite

View File

@@ -34,6 +34,7 @@
#include "graphicspart/partterminal.h"
#include "graphicspart/parttext.h"
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
#include "UndoCommand/deletepartscommand.h"
/**
@@ -71,29 +72,6 @@ class ElementEditionCommand : public QUndoCommand
ElementView *m_view;
};
/**
This command deletes one or several primitives/parts when editing an
electrical element.
*/
class DeletePartsCommand : public ElementEditionCommand {
// constructors, destructor
public:
DeletePartsCommand(ElementScene *, const QList<QGraphicsItem *>&, QUndoCommand * = nullptr);
~DeletePartsCommand() override;
private:
DeletePartsCommand(const DeletePartsCommand &);
// methods
public:
void undo() override;
void redo() override;
// attributes
private:
/// Deleted primitives
QList<QGraphicsItem *> deleted_parts;
};
/**
This command cut primitives when editing an electrical element.
*/
@@ -132,30 +110,6 @@ class MovePartsCommand : public ElementEditionCommand {
bool first_redo;
};
/**
This command adds a primitive when editing an electrical element.
*/
class AddPartCommand : public ElementEditionCommand {
// constructors, destructor
public:
AddPartCommand(const QString &, ElementScene *, QGraphicsItem *, QUndoCommand * = nullptr);
~AddPartCommand() override;
private:
AddPartCommand(const AddPartCommand &);
// methods
public:
void undo() override;
void redo() override;
// attributes
private:
/// Added primitive
QGraphicsItem *part;
/// Prevent the first call to redo()
bool first_redo;
};
/**
This command changes the translated names of an electrical element.
*/
@@ -311,5 +265,4 @@ private:
};
#endif

View File

@@ -119,7 +119,6 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
if (m_event_interface->isFinish()) {
delete m_event_interface;
m_event_interface = nullptr;
emit(partsAdded());
}
return;
}
@@ -151,7 +150,6 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e)
if (m_event_interface->isFinish()) {
delete m_event_interface;
m_event_interface = nullptr;
emit(partsAdded());
}
return;
}
@@ -171,7 +169,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
if (m_event_interface->isFinish()) {
delete m_event_interface;
m_event_interface = nullptr;
emit(partsAdded());
}
return;
}
@@ -199,7 +196,6 @@ void ElementScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
if (m_event_interface->isFinish()) {
delete m_event_interface;
m_event_interface = nullptr;
emit(partsAdded());
}
return;
}
@@ -223,7 +219,6 @@ void ElementScene::keyPressEvent(QKeyEvent *event)
{
delete m_event_interface;
m_event_interface = nullptr;
emit(partsAdded());
}
return;
}
@@ -725,6 +720,38 @@ QETElementEditor* ElementScene::editor() const
return m_element_editor;
}
/**
* @brief ElementScene::addItems
* Add items to the scene and emit partsAdded.
* Prefer always use this method instead of QGraphicsScene::addItem
* even if you want to add one item, for gain the signal emission
* @param items
*/
void ElementScene::addItems(QVector<QGraphicsItem *> items)
{
for (const auto &item : items) {
addItem(item);
}
emit partsAdded();
}
/**
* @brief ElementScene::removeItems
* Remove items from the scene and emit partsRemoved.
* Prefer always use this method instead of QGraphicsScene::removeItem
* even if you want to remove one item, for gain the signal emission
* @param items
*/
void ElementScene::removeItems(QVector<QGraphicsItem *> items)
{
for (const auto &item : items) {
removeItem(item);
}
emit partsRemoved();
}
/**
@brief ElementScene::slot_select
Select the item in content,
@@ -796,18 +823,15 @@ void ElementScene::slot_invertSelection()
*/
void ElementScene::slot_delete()
{
// check that there is something selected
// verifie qu'il y a qqc de selectionne
QList<QGraphicsItem *> selected_items = selectedItems();
if (selected_items.isEmpty()) return;
const auto selected_items{selectedItems().toVector()};
if (selected_items.isEmpty()) {
return;
}
// erase everything that is selected
// efface tout ce qui est selectionne
m_undo_stack.push(new DeletePartsCommand(this, selected_items));
// removing items does not trigger QGraphicsScene::selectionChanged()
emit(partsRemoved());
emit(selectionChanged());
// removing items does not trigger QGraphicsScene::selectionChanged()
emit selectionChanged();
}
/**

View File

@@ -37,6 +37,9 @@ class QKeyEvent;
This class is the canvas allowing the visual edition of an electrial element.
It displays the various primitives composing the drawing of the element,
the border due to its fixed size and its hotspot.
For add and remove item prefer use custom method addItems and removeItems instead of
addItem and removeItem, because these methods emit signal partAdded and partRemoved.
*/
class ElementScene : public QGraphicsScene
{
@@ -124,6 +127,8 @@ class ElementScene : public QGraphicsScene
void cut();
void copy();
QETElementEditor* editor() const;
void addItems(QVector<QGraphicsItem *> items);
void removeItems(QVector<QGraphicsItem *> items);
protected:
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;

View File

@@ -17,7 +17,7 @@
*/
#include "eseventaddarc.h"
#include "../editorcommands.h"
#include "../UndoCommand/addpartcommand.h"
#include "../elementscene.h"
#include "../graphicspart/partarc.h"

View File

@@ -17,7 +17,7 @@
*/
#include "eseventadddynamictextfield.h"
#include "../editorcommands.h"
#include "../UndoCommand/addpartcommand.h"
#include "../elementscene.h"
#include "../graphicspart/partdynamictextfield.h"

View File

@@ -17,7 +17,7 @@
*/
#include "eseventaddellipse.h"
#include "../editorcommands.h"
#include "../UndoCommand/addpartcommand.h"
#include "../elementscene.h"
#include "../graphicspart/partellipse.h"

View File

@@ -17,7 +17,7 @@
*/
#include "eseventaddline.h"
#include "../editorcommands.h"
#include "../UndoCommand/addpartcommand.h"
#include "../elementscene.h"
#include "../graphicspart/partline.h"
#include "../ui/qetelementeditor.h"

View File

@@ -17,7 +17,7 @@
*/
#include "eseventaddpolygon.h"
#include "../editorcommands.h"
#include "../UndoCommand/addpartcommand.h"
#include "../elementscene.h"
#include "../graphicspart/partpolygon.h"

View File

@@ -17,7 +17,7 @@
*/
#include "eseventaddrect.h"
#include "../editorcommands.h"
#include "../UndoCommand/addpartcommand.h"
#include "../elementscene.h"
#include "../graphicspart/partrectangle.h"

View File

@@ -17,7 +17,7 @@
*/
#include "eseventaddterminal.h"
#include "../editorcommands.h"
#include "../UndoCommand/addpartcommand.h"
#include "../elementscene.h"
#include "../graphicspart/partterminal.h"

View File

@@ -17,7 +17,7 @@
*/
#include "eseventaddtext.h"
#include "../editorcommands.h"
#include "../UndoCommand/addpartcommand.h"
#include "../elementscene.h"
#include "../graphicspart/parttext.h"

View File

@@ -46,6 +46,8 @@
#include "dynamictextfieldeditor.h"
#include "../../newelementwizard.h"
#include "../editorcommands.h"
#include "../../dxf/dxftoelmt.h"
#include "../UndoCommand/openelmtcommand.h"
#include <QSettings>
#include <QActionGroup>
@@ -1128,7 +1130,6 @@ void QETElementEditor::setupConnection()
});
connect(&(m_elmt_scene -> undoStack()), &QUndoStack::indexChanged, [this]() {
this->updatePartsList();
this->updateInformations();
});
}
@@ -1490,3 +1491,30 @@ void QETElementEditor::on_m_donate_action_triggered() {
}
void QETElementEditor::on_m_about_qt_action_triggered() { qApp->aboutQt(); }
void QETElementEditor::on_m_import_dxf_triggered()
{
if (dxf2ElmtIsPresent(true, this))
{
QString file_path{QFileDialog::getOpenFileName(this,
QObject::tr("Importer un fichier dxf"),
"/home",
"DXF (*.dxf)")};
if (file_path.isEmpty()) {
return;
}
QMessageBox::information(this, tr("Avertissement"), tr("L'import d'un dxf volumineux peut prendre du temps \n"
"veuillez patienter durant l'import..."));
const QByteArray array_{dxfToElmt(file_path)};
if (array_.isEmpty()) {
return;
}
QDomDocument xml_;
xml_.setContent(array_);
m_elmt_scene->undoStack().push(new OpenElmtCommand(xml_, m_elmt_scene));
}
}

View File

@@ -110,6 +110,7 @@ class QETElementEditor : public QMainWindow
void on_m_youtube_action_triggered();
void on_m_donate_action_triggered();
void on_m_about_qt_action_triggered();
void on_m_import_dxf_triggered();
private:
bool canClose();

View File

@@ -35,6 +35,7 @@
<addaction name="m_new_action"/>
<addaction name="m_open_action"/>
<addaction name="m_open_from_file_action"/>
<addaction name="m_import_dxf"/>
<addaction name="m_open_dxf_action"/>
<addaction name="m_save_action"/>
<addaction name="m_save_as_action"/>
@@ -501,6 +502,15 @@
<string>Space</string>
</property>
</action>
<action name="m_import_dxf">
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/run-dxf.png</normaloff>:/ico/16x16/run-dxf.png</iconset>
</property>
<property name="text">
<string>Importer un dxf</string>
</property>
</action>
</widget>
<resources>
<include location="../../../qelectrotech.qrc"/>

View File

@@ -86,6 +86,18 @@ void QGIManager::release(const QList<QGraphicsItem *> &qgis) {
foreach(QGraphicsItem *qgi, qgis) release(qgi);
}
void QGIManager::manage(const QVector<QGraphicsItem *> &items) {
for (const auto &qgi : items) {
manage(qgi);
}
}
void QGIManager::release(const QVector<QGraphicsItem *> &items) {
for (const auto &qgi : items) {
release(qgi);
}
}
/**
Indique au QGIManager de detruire les QGraphicsItem restants lors de sa
destruction si ceux-ci n'appartiennent pas a la scene

View File

@@ -42,8 +42,12 @@ class QGIManager {
public:
void manage(QGraphicsItem *);
void release(QGraphicsItem *);
void manage(const QList<QGraphicsItem *> &);
void release(const QList<QGraphicsItem *> &);
QT_DEPRECATED_X("Use QGIManager::manage(const QVector<QGraphicsItem *> &) instead")
void manage(const QList<QGraphicsItem *> &);
QT_DEPRECATED_X("Use QGIManager::release(const QVector<QGraphicsItem *> &) instead")
void release(const QList<QGraphicsItem *> &);
void manage(const QVector<QGraphicsItem *> &items);
void release(const QVector<QGraphicsItem *> &items);
void setDestroyQGIOnDelete(bool);
bool manages(QGraphicsItem *) const;
};

View File

@@ -0,0 +1,51 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "thirdpartybinaryinstalldialog.h"
#include "ui_thirdpartybinaryinstalldialog.h"
#include <QDialogButtonBox>
#include <QPushButton>
#include <QDesktopServices>
#include <QDir>
#include <QUrl>
ThirdPartyBinaryInstallDialog::ThirdPartyBinaryInstallDialog(const QString &text,
const QString &downloadLink,
const QString &binaryFolderPath,
QWidget *parent) :
QDialog{parent},
ui{new Ui::ThirdPartyBinaryInstallDialog}
{
ui->setupUi(this);
ui->m_label->setText(text);
connect(ui->m_download_pb, &QPushButton::clicked, [downloadLink](){
QDesktopServices::openUrl(QUrl(downloadLink));
});
connect(ui->m_install_dir_pb, &QPushButton::clicked, [binaryFolderPath]() {
//Make sure the path exist
QDir dir_;
dir_.mkpath(binaryFolderPath);
QDesktopServices::openUrl(QUrl("file:///" + binaryFolderPath));
});
}
ThirdPartyBinaryInstallDialog::~ThirdPartyBinaryInstallDialog()
{
delete ui;
}

View File

@@ -0,0 +1,42 @@
/*
Copyright 2006-2022 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech 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 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef THIRDPARTYBINARYINSTALLDIALOG_H
#define THIRDPARTYBINARYINSTALLDIALOG_H
#include <QDialog>
namespace Ui {
class ThirdPartyBinaryInstallDialog;
}
class ThirdPartyBinaryInstallDialog : public QDialog
{
Q_OBJECT
public:
explicit ThirdPartyBinaryInstallDialog(const QString &text,
const QString &downloadLink,
const QString &binaryFolderPath,
QWidget *parent = nullptr);
~ThirdPartyBinaryInstallDialog();
private:
Ui::ThirdPartyBinaryInstallDialog *ui;
};
#endif // THIRDPARTYBINARYINSTALLDIALOG_H

View File

@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ThirdPartyBinaryInstallDialog</class>
<widget class="QDialog" name="ThirdPartyBinaryInstallDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>373</width>
<height>64</height>
</rect>
</property>
<property name="windowTitle">
<string>Logiciel tiers requis</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="2">
<widget class="QDialogButtonBox" name="m_button_box">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="m_download_pb">
<property name="text">
<string>Télechargement</string>
</property>
<property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/16x16/edit-download.png</normaloff>:/ico/16x16/edit-download.png</iconset>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="m_install_dir_pb">
<property name="text">
<string>Dossier installation</string>
</property>
<property name="icon">
<iconset resource="../../qelectrotech.qrc">
<normaloff>:/ico/16x16/folder-open.png</normaloff>:/ico/16x16/folder-open.png</iconset>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="m_label">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="margin">
<number>5</number>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../qelectrotech.qrc"/>
</resources>
<connections>
<connection>
<sender>m_button_box</sender>
<signal>accepted()</signal>
<receiver>ThirdPartyBinaryInstallDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_button_box</sender>
<signal>rejected()</signal>
<receiver>ThirdPartyBinaryInstallDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>