mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-05-03 12:49:59 +02:00
makro
This commit is contained in:
@@ -119,8 +119,8 @@ int ElementCollectionItem::rowForInsertItem(const QString &name)
|
||||
return -1;
|
||||
|
||||
QList <ElementCollectionItem *> child;
|
||||
//The item to insert is an element we search from element child
|
||||
if (name.endsWith(".elmt"))
|
||||
//The item to insert is an element/template we search from element child
|
||||
if (name.endsWith(".elmt") || name.endsWith(".qetmak"))
|
||||
{
|
||||
child = elementsDirectChild();
|
||||
//There isn't element, we insert at last position
|
||||
|
||||
@@ -93,10 +93,7 @@ void ElementsCollectionWidget::addProject(QETProject *project)
|
||||
{
|
||||
if (m_model)
|
||||
{
|
||||
m_progress_bar->show();
|
||||
m_tree_view->setDisabled(true);
|
||||
QList <QETProject *> prj; prj.append(project);
|
||||
m_model->loadCollections(false, false, false, prj);
|
||||
m_model->addProject(project, true);
|
||||
}
|
||||
else {
|
||||
m_waiting_project.append(project);
|
||||
@@ -194,7 +191,7 @@ void ElementsCollectionWidget::setUpWidget()
|
||||
m_tree_view->setMouseTracking(true);
|
||||
m_tree_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
|
||||
//Setup the macros tree view (DEV)
|
||||
//Setup the macros tree view
|
||||
m_macros_tree_view = new ElementsTreeView(this);
|
||||
m_macros_tree_view->setHeaderHidden(true);
|
||||
m_macros_tree_view->setIconSize(QSize(50, 50));
|
||||
@@ -209,7 +206,7 @@ void ElementsCollectionWidget::setUpWidget()
|
||||
m_tab_widget->setDocumentMode(true);
|
||||
m_tab_widget->setTabPosition(QTabWidget::North);
|
||||
m_tab_widget->addTab(m_tree_view, tr("Collections"));
|
||||
m_tab_widget->addTab(m_macros_tree_view, tr("Modèles (DEV)"));
|
||||
m_tab_widget->addTab(m_macros_tree_view, tr("Modèles"));
|
||||
|
||||
m_main_vlayout->addWidget(m_search_field);
|
||||
m_main_vlayout->addWidget(m_tab_widget);
|
||||
@@ -258,11 +255,15 @@ void ElementsCollectionWidget::setUpConnection()
|
||||
this, &ElementsCollectionWidget::dirProperties);
|
||||
|
||||
connect(m_tree_view, &QTreeView::doubleClicked,
|
||||
[this](const QModelIndex &index)
|
||||
{
|
||||
this->m_index_at_context_menu = index ;
|
||||
this->editElement();
|
||||
});
|
||||
[this](const QModelIndex &index)
|
||||
{
|
||||
this->m_index_at_context_menu = index ;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(index);
|
||||
if (eci && eci->collectionPath().endsWith(".qetmak")) {
|
||||
return; // Do nothing on double click for macros
|
||||
}
|
||||
this->editElement();
|
||||
});
|
||||
|
||||
connect(m_tree_view, &QTreeView::entered,
|
||||
[this] (const QModelIndex &index) {
|
||||
@@ -276,11 +277,15 @@ void ElementsCollectionWidget::setUpConnection()
|
||||
this, &ElementsCollectionWidget::customContextMenu);
|
||||
|
||||
connect(m_macros_tree_view, &QTreeView::doubleClicked,
|
||||
[this](const QModelIndex &index)
|
||||
{
|
||||
this->m_index_at_context_menu = index ;
|
||||
this->editElement();
|
||||
});
|
||||
[this](const QModelIndex &index)
|
||||
{
|
||||
this->m_index_at_context_menu = index ;
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(index);
|
||||
if (eci && eci->collectionPath().endsWith(".qetmak")) {
|
||||
return; // Do nothing on double click for macros
|
||||
}
|
||||
this->editElement();
|
||||
});
|
||||
|
||||
connect(m_macros_tree_view, &QTreeView::entered,
|
||||
[this] (const QModelIndex &index) {
|
||||
@@ -310,7 +315,7 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point)
|
||||
m_index_at_context_menu);
|
||||
bool add_open_dir = false;
|
||||
|
||||
if (eci->isElement())
|
||||
if (eci->isElement() && !eci->collectionPath().endsWith(".qetmak"))
|
||||
m_context_menu->addAction(m_edit_element);
|
||||
|
||||
if (eci->type() == FileElementCollectionItem::Type)
|
||||
@@ -398,6 +403,9 @@ void ElementsCollectionWidget::editElement()
|
||||
|
||||
if ( !(eci && eci->isElement()) ) return;
|
||||
|
||||
// Prevent the element editor from opening for macros
|
||||
if (eci->collectionPath().endsWith(".qetmak")) return;
|
||||
|
||||
ElementsLocation location(eci->collectionPath());
|
||||
|
||||
QETApp *app = QETApp::instance();
|
||||
@@ -422,11 +430,15 @@ void ElementsCollectionWidget::deleteElement()
|
||||
if (!eci) return;
|
||||
|
||||
ElementsLocation loc(eci->collectionPath());
|
||||
if (! (loc.isElement()
|
||||
&& loc.exist()
|
||||
&& loc.isFileSystem()
|
||||
&& (loc.collectionPath().startsWith("company://")
|
||||
|| loc.collectionPath().startsWith("custom://"))) ) return;
|
||||
|
||||
bool isDeletableFile = loc.isElement() || eci->collectionPath().endsWith(".qetmak");
|
||||
|
||||
if (! (isDeletableFile
|
||||
&& loc.exist()
|
||||
&& loc.isFileSystem()
|
||||
&& (loc.collectionPath().startsWith("company://")
|
||||
|| loc.collectionPath().startsWith("custom://")
|
||||
|| loc.collectionPath().startsWith("macros://"))) ) return;
|
||||
|
||||
if (QET::QetMessageBox::question(
|
||||
this,
|
||||
@@ -468,10 +480,11 @@ void ElementsCollectionWidget::deleteDirectory()
|
||||
|
||||
ElementsLocation loc (eci->collectionPath());
|
||||
if (! (loc.isDirectory()
|
||||
&& loc.exist()
|
||||
&& loc.isFileSystem()
|
||||
&& (loc.collectionPath().startsWith("company://")
|
||||
|| loc.collectionPath().startsWith("custom://"))) ) return;
|
||||
&& loc.exist()
|
||||
&& loc.isFileSystem()
|
||||
&& (loc.collectionPath().startsWith("company://")
|
||||
|| loc.collectionPath().startsWith("custom://")
|
||||
|| loc.collectionPath().startsWith("macros://"))) ) return;
|
||||
|
||||
if (QET::QetMessageBox::question(
|
||||
this,
|
||||
|
||||
@@ -297,7 +297,7 @@ void ElementsLocation::setPath(const QString &path)
|
||||
else
|
||||
{
|
||||
QString path_ = path;
|
||||
if(path_.endsWith(".elmt"))
|
||||
if(path_.endsWith(".elmt") || path_.endsWith(".qetmak"))
|
||||
{
|
||||
m_file_system_path = path_;
|
||||
if (path_.startsWith(QETApp::commonElementsDirN()))
|
||||
@@ -366,10 +366,11 @@ void ElementsLocation::setPath(const QString &path)
|
||||
*/
|
||||
bool ElementsLocation::addToPath(const QString &string)
|
||||
{
|
||||
if (m_collection_path.endsWith(".elmt", Qt::CaseInsensitive))
|
||||
if (m_collection_path.endsWith(".elmt", Qt::CaseInsensitive) ||
|
||||
m_collection_path.endsWith(".qetmak", Qt::CaseInsensitive))
|
||||
{
|
||||
qDebug() << "ElementsLocation::addToPath :"
|
||||
" Can't add string to the path of an element";
|
||||
" Can't add string to the path of an element or template";
|
||||
return(false);
|
||||
}
|
||||
|
||||
@@ -472,7 +473,7 @@ QString ElementsLocation::toString() const
|
||||
*/
|
||||
bool ElementsLocation::isElement() const
|
||||
{
|
||||
return m_collection_path.endsWith(".elmt");
|
||||
return m_collection_path.endsWith(".elmt") || m_collection_path.endsWith(".qetmak");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,12 @@
|
||||
#include "../qeticons.h"
|
||||
#include "elementcollectionitem.h"
|
||||
#include "elementslocation.h"
|
||||
|
||||
#include "../qetproject.h"
|
||||
#include "../diagram.h"
|
||||
#include "xmlelementcollection.h"
|
||||
#include "../nameslist.h"
|
||||
#include <QPainter>
|
||||
#include <QScopedPointer>
|
||||
#include <QDrag>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
@@ -95,9 +100,107 @@ void ElementsTreeView::startElementDrag(const ElementsLocation &location)
|
||||
if (location.isDirectory())
|
||||
{
|
||||
mime_data->setData("application/x-qet-category-uri",
|
||||
location_str.toLatin1());
|
||||
location_str.toLatin1());
|
||||
drag->setPixmap(QET::Icons::Folder.pixmap(22, 22));
|
||||
}
|
||||
else if (location.fileName().endsWith(".qetmak"))
|
||||
{
|
||||
mime_data->setData("application/x-qet-element-uri", location_str.toLatin1());
|
||||
|
||||
QPixmap macro_pixmap;
|
||||
|
||||
// --- MINI-RENDERER FÜR DAS MAKRO-VORSCHAUBILD ---
|
||||
QFile file(location.fileSystemPath());
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QDomDocument macro_doc;
|
||||
if (macro_doc.setContent(&file)) {
|
||||
QDomElement root = macro_doc.documentElement();
|
||||
if (root.tagName() == "qet_macro") {
|
||||
|
||||
// 1. Unsichtbares Dummy-Projekt erstellen
|
||||
QScopedPointer<QETProject> dummy_project(new QETProject());
|
||||
|
||||
// 2. Bauteile in das Dummy-Projekt laden (wie beim echten Drop)
|
||||
QDomElement collection_node = root.firstChildElement("collection");
|
||||
if (!collection_node.isNull()) {
|
||||
QDomNodeList elements = collection_node.elementsByTagName("element");
|
||||
for (int i = 0; i < elements.count(); ++i) {
|
||||
QDomElement elmt_node = elements.at(i).toElement();
|
||||
QString path = elmt_node.attribute("path");
|
||||
QDomElement definition = elmt_node.firstChildElement("definition");
|
||||
if (!path.isEmpty() && !definition.isNull()) {
|
||||
int last_slash = path.lastIndexOf('/');
|
||||
QString dir_path = (last_slash != -1) ? path.left(last_slash) : "";
|
||||
QString file_name = (last_slash != -1) ? path.mid(last_slash + 1) : path;
|
||||
|
||||
if (!dir_path.isEmpty()) {
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
||||
QStringList parts = dir_path.split('/', QString::SkipEmptyParts);
|
||||
#else
|
||||
QStringList parts = dir_path.split('/', Qt::SkipEmptyParts);
|
||||
#endif
|
||||
QString current_path = "";
|
||||
for (const QString &part : parts) {
|
||||
QString parent_path = current_path;
|
||||
if (!current_path.isEmpty()) current_path += "/";
|
||||
current_path += part;
|
||||
if (current_path == "import") continue;
|
||||
NamesList empty_names;
|
||||
dummy_project->embeddedElementCollection()->createDir(parent_path, part, empty_names);
|
||||
}
|
||||
}
|
||||
dummy_project->embeddedElementCollection()->addElementDefinition(dir_path, file_name, definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Diagram *dummy_diagram = dummy_project->addNewDiagram();
|
||||
|
||||
// 4. Makro auf dem unsichtbaren Blatt zeichnen
|
||||
QDomElement diagram_content_node = root.firstChildElement("diagram_content");
|
||||
QDomElement diagram_node = diagram_content_node.firstChildElement("diagram");
|
||||
if (!diagram_node.isNull()) {
|
||||
QDomNodeList instances = diagram_node.elementsByTagName("element");
|
||||
for (int i = 0; i < instances.count(); ++i) {
|
||||
QDomElement inst = instances.at(i).toElement();
|
||||
QString type = inst.attribute("type");
|
||||
if (type.startsWith("macro://")) {
|
||||
inst.setAttribute("type", type.replace("macro://", "embed://"));
|
||||
}
|
||||
}
|
||||
|
||||
dummy_diagram->fromXml(diagram_node, QPointF(0, 0), false, nullptr);
|
||||
dummy_diagram->clearSelection();
|
||||
|
||||
// 5. "Screenshot" (Pixmap) von den gezeichneten Elementen machen
|
||||
QRectF scene_rect = dummy_diagram->itemsBoundingRect();
|
||||
if (!scene_rect.isEmpty()) {
|
||||
scene_rect.adjust(-5, -5, 5, 5); // Kleiner Rand
|
||||
macro_pixmap = QPixmap(scene_rect.size().toSize());
|
||||
macro_pixmap.fill(Qt::transparent); // Transparenter Hintergrund
|
||||
|
||||
QPainter painter(¯o_pixmap);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
dummy_diagram->render(&painter, macro_pixmap.rect(), scene_rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (macro_pixmap.isNull()) {
|
||||
macro_pixmap = QET::Icons::Project.pixmap(32, 32);
|
||||
}
|
||||
|
||||
// Bild verkleinern, falls das Makro gigantisch groß ist
|
||||
if (macro_pixmap.width() > MAX_DND_PIXMAP_WIDTH || macro_pixmap.height() > MAX_DND_PIXMAP_HEIGHT) {
|
||||
macro_pixmap = macro_pixmap.scaled(MAX_DND_PIXMAP_WIDTH, MAX_DND_PIXMAP_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
drag->setPixmap(macro_pixmap);
|
||||
// Bild zentriert an die Maus hängen
|
||||
drag->setHotSpot(QPoint(macro_pixmap.width() / 2, macro_pixmap.height() / 2));
|
||||
}
|
||||
else if (location.isElement())
|
||||
{
|
||||
mime_data->setData("application/x-qet-element-uri",
|
||||
|
||||
@@ -93,7 +93,7 @@ QString FileElementCollectionItem::dirPath() const
|
||||
*/
|
||||
bool FileElementCollectionItem::isDir() const
|
||||
{
|
||||
if (m_path.endsWith(".elmt"))
|
||||
if (m_path.endsWith(".elmt") || m_path.endsWith(".qetmak"))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
@@ -120,7 +120,6 @@ QString FileElementCollectionItem::localName()
|
||||
|
||||
else if (isDir()) {
|
||||
if (isCollectionRoot()) {
|
||||
// --- NEU: Makro-Pfad laden ---
|
||||
QString macrosPath = QETApp::userMacrosDir();
|
||||
if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1);
|
||||
|
||||
@@ -130,7 +129,7 @@ QString FileElementCollectionItem::localName()
|
||||
setText(QObject::tr("Collection Company"));
|
||||
else if (m_path == QETApp::customElementsDirN())
|
||||
setText(QObject::tr("Collection utilisateur"));
|
||||
else if (m_path == macrosPath) // <-- NEU: Name des Ordners zuweisen
|
||||
else if (m_path == macrosPath)
|
||||
setText(QObject::tr("Makros"));
|
||||
else
|
||||
setText(QObject::tr("Collection inconnue"));
|
||||
@@ -153,7 +152,11 @@ QString FileElementCollectionItem::localName()
|
||||
}
|
||||
else if (isElement()) {
|
||||
ElementsLocation loc(collectionPath());
|
||||
setText(loc.name());
|
||||
QString display_name = loc.name();
|
||||
if (display_name.endsWith(".qetmak")) {
|
||||
display_name.remove(".qetmak");
|
||||
}
|
||||
setText(display_name);
|
||||
}
|
||||
|
||||
return text();
|
||||
@@ -175,7 +178,12 @@ QString FileElementCollectionItem::localName(const ElementsLocation &location)
|
||||
localName();
|
||||
}
|
||||
else if (isElement()) {
|
||||
setText(location.name());
|
||||
QString display_name = location.name();
|
||||
// Schneide die Endung .qetmak für die Anzeige ab
|
||||
if (display_name.endsWith(".qetmak")) {
|
||||
display_name.remove(".qetmak");
|
||||
}
|
||||
setText(display_name);
|
||||
}
|
||||
|
||||
return text();
|
||||
@@ -237,7 +245,7 @@ bool FileElementCollectionItem::isCollectionRoot() const
|
||||
if (m_path == QETApp::commonElementsDirN()
|
||||
|| m_path == QETApp::companyElementsDirN()
|
||||
|| m_path == QETApp::customElementsDirN()
|
||||
|| m_path == macrosPath) // <-- NEU: Makros sind jetzt ein echtes Root-Verzeichnis
|
||||
|| m_path == macrosPath)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
@@ -367,13 +375,13 @@ void FileElementCollectionItem::setUpIcon()
|
||||
@param hide_element
|
||||
*/
|
||||
void FileElementCollectionItem::setPathName(const QString& path_name,
|
||||
bool set_data,
|
||||
bool hide_element)
|
||||
bool set_data,
|
||||
bool hide_element)
|
||||
{
|
||||
m_path = path_name;
|
||||
|
||||
//This isn't an element, we create the childs
|
||||
if (!path_name.endsWith(".elmt"))
|
||||
//This isn't an element or template, we create the childs
|
||||
if (!path_name.endsWith(".elmt") && !path_name.endsWith(".qetmak"))
|
||||
populate(set_data, hide_element);
|
||||
}
|
||||
|
||||
@@ -402,9 +410,9 @@ void FileElementCollectionItem::populate(bool set_data, bool hide_element)
|
||||
return;
|
||||
|
||||
//Get all elmt file in this directory
|
||||
dir.setNameFilters(QStringList() << "*.elmt");
|
||||
dir.setNameFilters(QStringList() << "*.elmt" << "*.qetmak");
|
||||
for (auto& str :
|
||||
dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
|
||||
dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
|
||||
{
|
||||
FileElementCollectionItem *feci = new FileElementCollectionItem();
|
||||
appendRow(feci);
|
||||
|
||||
Reference in New Issue
Block a user