Merge branch 'master' into qt6_cmake_joshua

This commit is contained in:
joshua
2026-05-05 20:09:51 +02:00
118 changed files with 64023 additions and 19853 deletions

View File

@@ -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

View File

@@ -259,10 +259,12 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data,
@param projects : list of projects to load
*/
void ElementsCollectionModel::loadCollections(bool common_collection,
bool company_collection,
bool custom_collection,
QList<QETProject *> projects)
bool company_collection,
bool custom_collection,
QList<QETProject *> projects)
{
clear();
m_items_list_to_setUp.clear();
if (common_collection)
@@ -275,17 +277,17 @@ void ElementsCollectionModel::loadCollections(bool common_collection,
if (common_collection || company_collection || custom_collection)
m_items_list_to_setUp.append(items());
for (QETProject *project : projects)
{
addProject(project, false);
m_items_list_to_setUp.append(projectItems(project));
}
auto *watcher = new QFutureWatcher<void>();
connect(watcher, &QFutureWatcher<void>::progressValueChanged,
this, &ElementsCollectionModel::loadingProgressValueChanged);
this, &ElementsCollectionModel::loadingProgressValueChanged);
connect(watcher, &QFutureWatcher<void>::progressRangeChanged,
this, &ElementsCollectionModel::loadingProgressRangeChanged);
this, &ElementsCollectionModel::loadingProgressRangeChanged);
connect(watcher, &QFutureWatcher<void>::finished,
this, &ElementsCollectionModel::loadingFinished);
connect(
@@ -298,6 +300,41 @@ void ElementsCollectionModel::loadCollections(bool common_collection,
watcher->setFuture(m_future);
}
/**
* @brief ElementsCollectionModel::loadMacrosCollection
* Load the macros collection synchronously to avoid thread-collisions.
*/
void ElementsCollectionModel::loadMacrosCollection()
{
m_items_list_to_setUp.clear();
addMacrosCollection(true);
}
/**
* @brief ElementsCollectionModel::addMacrosCollection
* Add the user macros collection to this model
* @param set_data
*/
void ElementsCollectionModel::addMacrosCollection(bool set_data)
{
QString macrosPath = QETApp::userMacrosDir();
qDebug() << "=== MAKRO PFAD CHECK ===" << macrosPath;
if (macrosPath.endsWith("/")) {
macrosPath.remove(macrosPath.length() - 1, 1);
}
FileElementCollectionItem *feci = new FileElementCollectionItem();
if (feci->setRootPath(macrosPath,
set_data,
m_hide_element)) {
invisibleRootItem()->appendRow(feci);
if (set_data)
feci->setUpData();
}
else
delete feci;
}
/**
@brief ElementsCollectionModel::addCommonCollection
Add the common elements collection to this model
@@ -356,11 +393,11 @@ void ElementsCollectionModel::addCustomCollection(bool set_data)
}
/**
@brief ElementsCollectionModel::addLocation
Add the element or directory to this model.
If the location is already managed by this model, do nothing.
@param location
*/
* @brief ElementsCollectionModel::addLocation
* Add the element or directory to this model.
* If the location is already managed by this model, do nothing.
* @param location
*/
void ElementsCollectionModel::addLocation(const ElementsLocation& location)
{
QModelIndex index = indexFromLocation(location);
@@ -375,14 +412,15 @@ void ElementsCollectionModel::addLocation(const ElementsLocation& location)
if (project) {
XmlProjectElementCollectionItem *xpeci =
m_project_hash.value(project);
m_project_hash.value(project);
last_item = xpeci->lastItemForPath(
location.collectionPath(false),
collection_name);
location.collectionPath(false),
collection_name);
}
}
else if (location.isCustomCollection()) {
// ANPASSUNG: Makros und Custom Collection werden hier behandelt!
else if (location.isCustomCollection() || location.isMacrosCollection()) {
QList <ElementCollectionItem *> child_list;
for (int i=0 ; i<rowCount() ; i++)
@@ -392,15 +430,18 @@ void ElementsCollectionModel::addLocation(const ElementsLocation& location)
if (eci->type() == FileElementCollectionItem::Type) {
FileElementCollectionItem *feci =
static_cast<FileElementCollectionItem *>(eci);
static_cast<FileElementCollectionItem *>(eci);
// Wir prüfen explizit, ob es Custom ODER Macros ist, und weisen es richtig zu.
if ((location.isCustomCollection() && feci->isCustomCollection()) ||
(location.isMacrosCollection() && feci->isMacrosCollection())) {
if (feci->isCustomCollection()) {
last_item = feci->lastItemForPath(
location.collectionPath(false),
collection_name);
location.collectionPath(false),
collection_name);
if(last_item)
break;
}
}
}
}
}
@@ -562,14 +603,14 @@ void ElementsCollectionModel::hideElement()
}
/**
@brief ElementsCollectionModel::indexFromLocation
Return the index who represent location.
Index can be non valid
@param location
@return
*/
* @brief ElementsCollectionModel::indexFromLocation
* Return the index who represent location.
* Index can be non valid
* @param location
* @return
*/
QModelIndex ElementsCollectionModel::indexFromLocation(
const ElementsLocation &location)
const ElementsLocation &location)
{
QList <ElementCollectionItem *> child_list;
@@ -577,30 +618,34 @@ QModelIndex ElementsCollectionModel::indexFromLocation(
child_list.append(static_cast<ElementCollectionItem *>(item(i)));
}
foreach(ElementCollectionItem *eci, child_list) {
foreach(ElementCollectionItem *eci, child_list) {
ElementCollectionItem *match_eci = nullptr;
ElementCollectionItem *match_eci = nullptr;
if (eci->type() == FileElementCollectionItem::Type) {
if (FileElementCollectionItem *feci = static_cast<FileElementCollectionItem *>(eci)) {
if ( (location.isCommonCollection() && feci->isCommonCollection()) ||
(location.isCompanyCollection() && feci->isCompanyCollection()) ||
(location.isCustomCollection() && !feci->isCommonCollection()) ) {
match_eci = feci->itemAtPath(location.collectionPath(false));
if (eci->type() == FileElementCollectionItem::Type) {
if (FileElementCollectionItem *feci = static_cast<FileElementCollectionItem *>(eci)) {
// ANPASSUNG: Makro-Prüfung hinzugefügt, damit das Modell den Pfad im Baum findet!
if ( (location.isCommonCollection() && feci->isCommonCollection()) ||
(location.isCompanyCollection() && feci->isCompanyCollection()) ||
(location.isMacrosCollection() && feci->isMacrosCollection()) ||
(location.isCustomCollection() && feci->isCustomCollection()) ) {
match_eci = feci->itemAtPath(location.collectionPath(false));
}
}
}
else if (eci->type() == XmlProjectElementCollectionItem::Type) {
if (XmlProjectElementCollectionItem *xpeci = static_cast<XmlProjectElementCollectionItem *>(eci)) {
match_eci = xpeci->itemAtPath(location.collectionPath(false));
}
}
else if (eci->type() == XmlProjectElementCollectionItem::Type) {
if (XmlProjectElementCollectionItem *xpeci = static_cast<XmlProjectElementCollectionItem *>(eci)) {
match_eci = xpeci->itemAtPath(location.collectionPath(false));
}
if (match_eci)
return indexFromItem(match_eci);
}
return QModelIndex();
if (match_eci)
return indexFromItem(match_eci);
}
return QModelIndex();
}
/**

View File

@@ -47,6 +47,8 @@ class ElementsCollectionModel : public QStandardItemModel
void addCommonCollection(bool set_data = true);
void addCompanyCollection(bool set_data = true);
void addCustomCollection(bool set_data = true);
void addMacrosCollection(bool set_data = true);
void loadMacrosCollection();
void addLocation(const ElementsLocation& location);
void addProject(QETProject *project, bool set_data = true);

View File

@@ -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);
@@ -176,16 +173,14 @@ void ElementsCollectionWidget::setUpAction()
*/
void ElementsCollectionWidget::setUpWidget()
{
//Setup the main layout
m_main_vlayout = new QVBoxLayout(this);
this->setLayout(m_main_vlayout);
m_main_vlayout->setContentsMargins(0, 0, 0, 0);
m_main_vlayout->setSpacing(2);
m_search_field = new QLineEdit(this);
m_search_field->setPlaceholderText(tr("Rechercher"));
m_search_field->setPlaceholderText(tr("Rechercher..."));
m_search_field->setClearButtonEnabled(true);
m_main_vlayout->addWidget(m_search_field);
//Setup the tree view
m_tree_view = new ElementsTreeView(this);
m_tree_view->setHeaderHidden(true);
m_tree_view->setIconSize(QSize(50, 50));
@@ -195,12 +190,29 @@ void ElementsCollectionWidget::setUpWidget()
m_tree_view->setAnimated(true);
m_tree_view->setMouseTracking(true);
m_tree_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_main_vlayout->addWidget(m_tree_view);
//Setup the progress bar
//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));
m_macros_tree_view->setDragDropMode(QAbstractItemView::DragDrop);
m_macros_tree_view->setContextMenuPolicy(Qt::CustomContextMenu);
m_macros_tree_view->setAutoExpandDelay(500);
m_macros_tree_view->setAnimated(true);
m_macros_tree_view->setMouseTracking(true);
m_macros_tree_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_tab_widget = new QTabWidget(this);
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"));
m_main_vlayout->addWidget(m_search_field);
m_main_vlayout->addWidget(m_tab_widget);
m_progress_bar = new QProgressBar(this);
m_progress_bar->setFormat(QObject::tr("chargement %p% (%v sur %m)"));
m_main_vlayout->addWidget(m_progress_bar);
m_progress_bar->hide();
@@ -243,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) {
@@ -256,37 +272,64 @@ void ElementsCollectionWidget::setUpConnection()
if (qde && eci)
qde->statusBar()->showMessage(eci->localName());
});
connect(m_macros_tree_view, &QTreeView::customContextMenuRequested,
this, &ElementsCollectionWidget::customContextMenu);
connect(m_macros_tree_view, &QTreeView::doubleClicked,
[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) {
QETDiagramEditor *qde = QETApp::diagramEditorAncestorOf(this);
ElementCollectionItem *eci = elementCollectionItemForIndex(index);
if (qde && eci)
qde->statusBar()->showMessage(eci->localName());
});
}
/**
@brief ElementsCollectionWidget::customContextMenu
Display the context menu of this widget at point
@param point
*/
* @brief ElementsCollectionWidget::customContextMenu
* Display the context menu of this widget at point
* @param point
*/
void ElementsCollectionWidget::customContextMenu(const QPoint &point)
{
m_index_at_context_menu = m_tree_view->indexAt(point);
QTreeView *clicked_tree = qobject_cast<QTreeView *>(sender());
if (!clicked_tree) clicked_tree = m_tree_view; // Fallback
m_index_at_context_menu = clicked_tree->indexAt(point);
if (!m_index_at_context_menu.isValid()) return;
m_context_menu->clear();
ElementCollectionItem *eci = elementCollectionItemForIndex(
m_index_at_context_menu);
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)
{
add_open_dir = true;
FileElementCollectionItem *feci =
static_cast<FileElementCollectionItem*>(eci);
static_cast<FileElementCollectionItem*>(eci);
if (!feci->isCommonCollection())
{
if (feci->isDir())
{
m_context_menu->addAction(m_new_element);
if (!feci->isMacrosCollection()) {
m_context_menu->addAction(m_new_element);
}
m_context_menu->addAction(m_new_directory);
if (!feci->isCollectionRoot())
{
@@ -301,7 +344,7 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point)
if (eci->type() == XmlProjectElementCollectionItem::Type)
{
XmlProjectElementCollectionItem *xpeci =
static_cast<XmlProjectElementCollectionItem *>(eci);
static_cast<XmlProjectElementCollectionItem *>(eci);
if (xpeci->isCollectionRoot())
add_open_dir = true;
}
@@ -320,7 +363,7 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point)
m_context_menu->addAction(m_open_dir);
m_context_menu->addAction(m_reload);
m_context_menu->popup(mapToGlobal(m_tree_view->mapToParent(point)));
m_context_menu->popup(mapToGlobal(clicked_tree->mapToParent(point)));
}
/**
@@ -360,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();
@@ -384,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,
@@ -400,9 +450,10 @@ void ElementsCollectionWidget::deleteElement()
QFile file(loc.fileSystemPath());
if (file.remove())
{
m_model->removeRows(m_index_at_context_menu.row(),
1,
m_index_at_context_menu.parent());
QAbstractItemModel *clicked_model = const_cast<QAbstractItemModel*>(m_index_at_context_menu.model());
if (clicked_model) {
clicked_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
}
}
else
{
@@ -429,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,
@@ -445,9 +497,10 @@ void ElementsCollectionWidget::deleteDirectory()
QDir dir (loc.fileSystemPath());
if (dir.removeRecursively())
{
m_model->removeRows(m_index_at_context_menu.row(),
1,
m_index_at_context_menu.parent());
QAbstractItemModel *clicked_model = const_cast<QAbstractItemModel*>(m_index_at_context_menu.model());
if (clicked_model) {
clicked_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
}
}
else
{
@@ -489,19 +542,29 @@ void ElementsCollectionWidget::editDirectory()
*/
void ElementsCollectionWidget::newDirectory()
{
ElementCollectionItem *eci = elementCollectionItemForIndex(
m_index_at_context_menu);
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
if (eci->type() != FileElementCollectionItem::Type) return;
if (!eci || eci->type() != FileElementCollectionItem::Type) return;
FileElementCollectionItem *feci =
static_cast<FileElementCollectionItem*>(eci);
FileElementCollectionItem *feci = static_cast<FileElementCollectionItem*>(eci);
if(feci->isCommonCollection()) return;
ElementsLocation location(feci->collectionPath());
ElementsCategoryEditor new_dir_editor(location, false, this);
if (new_dir_editor.exec() == QDialog::Accepted)
m_model->addLocation(new_dir_editor.createdLocation());
if (new_dir_editor.exec() == QDialog::Accepted) {
ElementsLocation new_loc = new_dir_editor.createdLocation();
if (new_loc.isMacrosCollection()) {
if (m_macros_model) {
m_macros_model->addLocation(new_loc);
}
} else {
if (m_model) {
m_model->addLocation(new_loc);
}
}
}
}
/**
@@ -662,12 +725,19 @@ void ElementsCollectionWidget::reload()
&ElementsCollectionWidget::loadingFinished);
m_new_model->loadCollections(true, true, true, project_list);
if (m_macros_model) {
m_macros_model->deleteLater();
}
m_macros_model = new ElementsCollectionModel(m_macros_tree_view);
m_macros_tree_view->setModel(m_macros_model);
m_macros_model->loadMacrosCollection();
}
/**
@brief ElementsCollectionWidget::loadingFinished
Process when collection finished to be loaded
*/
* @brief ElementsCollectionWidget::loadingFinished
* Process when collection finished to be loaded
*/
void ElementsCollectionWidget::loadingFinished()
{
if (m_new_model)
@@ -836,15 +906,21 @@ void ElementsCollectionWidget::showAndExpandItem(const QModelIndex &index,
}
/**
@brief ElementsCollectionWidget::elementCollectionItemForIndex
@param index
@return The internal pointer of index casted to ElementCollectionItem;
*/
ElementCollectionItem *ElementsCollectionWidget::elementCollectionItemForIndex(
const QModelIndex &index) {
if (!index.isValid())
return nullptr;
* @brief ElementsCollectionWidget::elementCollectionItemForIndex
* @param index
* @return The internal pointer of index casted to ElementCollectionItem;
*/
ElementCollectionItem *ElementsCollectionWidget::elementCollectionItemForIndex(const QModelIndex &index)
{
if (!index.isValid()) return nullptr;
return static_cast<ElementCollectionItem*>(
m_model->itemFromIndex(index));
if (m_macros_model && index.model() == m_macros_model) {
return static_cast<ElementCollectionItem *>(m_macros_model->itemFromIndex(index));
}
if (m_model && index.model() == m_model) {
return static_cast<ElementCollectionItem *>(m_model->itemFromIndex(index));
}
return nullptr;
}

View File

@@ -25,6 +25,8 @@
#include <QTimer>
#include <QElapsedTimer>
#include <QScopedPointer>
#include <QTabWidget>
#include <QTreeView>
class ElementsCollectionModel;
class QVBoxLayout;
@@ -90,9 +92,12 @@ class ElementsCollectionWidget : public QWidget
private:
ElementsCollectionModel *m_model = nullptr;
ElementsCollectionModel *m_new_model = nullptr;
ElementsCollectionModel *m_macros_model = nullptr;
QLineEdit *m_search_field;
QTimer m_search_timer;
ElementsTreeView *m_tree_view;
ElementsTreeView *m_macros_tree_view = nullptr;
QTabWidget *m_tab_widget = nullptr;
QVBoxLayout *m_main_vlayout;
QMenu *m_context_menu;
QModelIndex m_index_at_context_menu;

View File

@@ -181,7 +181,7 @@ QString ElementsLocation::collectionPath(bool protocol) const
else
{
QString path = m_collection_path;
return path.remove(QRegularExpression("common://|company://|custom://|embed://"));
return path.remove(QRegularExpression("common://|company://|custom://|macros://|embed://"));
}
}
@@ -232,54 +232,34 @@ QString ElementsLocation::path() const
(start by common://, company://, custom:// or embed://) or not.
@param path
*/
void ElementsLocation::setPath(const QString &path)
{
QString tmp_path = path;
#ifdef Q_OS_WIN32
//On windows, we convert backslash to slash
#ifdef Q_OS_WIN32
tmp_path = QDir::fromNativeSeparators(path);
#endif
#endif
QString macrosPath = QETApp::userMacrosDir();
if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1);
//There is a project, the path is for an embedded coolection.
if (m_project)
{
m_collection_path = path;
//Add the protocol to the collection path
if (!path.startsWith("embed://"))
m_collection_path.prepend("embed://");
}
//The path start with project, we get the project and the path from the string
else if (tmp_path.startsWith("project"))
{
QRegularExpression re
("^project(?<project_id>[0-9])\\+(?<collection_path>embed://*.*)$");
if (!re.isValid())
{
qWarning() <<QObject::tr("this is an error in the code")
<< re.errorString()
<< re.patternErrorOffset();
return;
}
QRegularExpression re ("^project(?<project_id>[0-9])\\+(?<collection_path>embed://*.*)$");
if (!re.isValid()) return;
QRegularExpressionMatch match = re.match(tmp_path);
if (!match.hasMatch())
{
qDebug()<<"no Match => return"
<<tmp_path;
return;
}
if (!match.hasMatch()) return;
bool conv_ok;
uint project_id = match.captured("project_id").toUInt(&conv_ok);
if (!conv_ok)
{
qWarning()<<"toUint failed"
<<match.captured("project_id")
<<re
<<tmp_path;
return;
}
if (!conv_ok) return;
QETProject *project = QETApp::project(project_id);
if (project)
{
@@ -287,10 +267,7 @@ void ElementsLocation::setPath(const QString &path)
m_project = project;
}
}
// The path is in file system,
// the given path is relative to common or custom collection
else if (path.startsWith("common://") || path.startsWith("company://") || path.startsWith("custom://"))
else if (path.startsWith("common://") || path.startsWith("company://") || path.startsWith("custom://") || path.startsWith("macros://"))
{
QString p;
if (path.startsWith("common://"))
@@ -303,6 +280,11 @@ void ElementsLocation::setPath(const QString &path)
tmp_path.remove("company://");
p = QETApp::companyElementsDirN() % "/" % tmp_path;
}
else if (path.startsWith("macros://"))
{
tmp_path.remove("macros://");
p = macrosPath % "/" % tmp_path;
}
else
{
tmp_path.remove("custom://");
@@ -312,11 +294,10 @@ void ElementsLocation::setPath(const QString &path)
m_file_system_path = p;
m_collection_path = path;
}
//In this case, the path is supposed to be relative to the file system.
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()))
@@ -331,6 +312,13 @@ void ElementsLocation::setPath(const QString &path)
path_.prepend("company://");
m_collection_path = path_;
}
else if (path_.startsWith(macrosPath))
{
QString matchPath = macrosPath + "/";
path_.remove(matchPath);
path_.prepend("macros://");
m_collection_path = path_;
}
else if (path_.startsWith(QETApp::customElementsDirN()))
{
path_.remove(QETApp::customElementsDirN()+="/");
@@ -353,6 +341,13 @@ void ElementsLocation::setPath(const QString &path)
path_.prepend("company://");
m_collection_path = path_;
}
else if (path_.startsWith(macrosPath))
{
QString matchPath = macrosPath + "/";
path_.remove(matchPath);
path_.prepend("macros://");
m_collection_path = path_;
}
else if (path_.startsWith(QETApp::customElementsDirN()))
{
path_.remove(QETApp::customElementsDirN()+="/");
@@ -371,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);
}
@@ -477,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");
}
/**
@@ -942,3 +938,14 @@ QDebug operator<< (QDebug debug, const ElementsLocation &location)
return debug;
}
/**
* @brief ElementsLocation::isMacrosCollection
* @return True if this location represent an item from the macros collection
*/
bool ElementsLocation::isMacrosCollection() const
{
QString macrosPath = QETApp::userMacrosDir();
if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1);
return fileSystemPath().startsWith(macrosPath);
}

View File

@@ -78,6 +78,7 @@ class ElementsLocation
bool isCommonCollection() const;
bool isCompanyCollection() const;
bool isCustomCollection() const;
bool isMacrosCollection() const;
bool isProject() const;
bool exist() const;
bool isWritable() const;

View File

@@ -22,7 +22,12 @@
#include "../qeticons.h"
#include "elementcollectionitem.h"
#include "elementslocation.h"
#include "../qetproject.h"
#include "../diagram.h"
#include "xmlelementcollection.h"
#include "../NameList/nameslist.h"
#include <QPainter>
#include <QScopedPointer>
#include <QDrag>
#include <QStandardItemModel>
@@ -91,9 +96,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(&macro_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",

View File

@@ -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;
@@ -110,9 +110,9 @@ bool FileElementCollectionItem::isElement() const
}
/**
@brief FileElementCollectionItem::localName
@return the located name of this item
*/
* @brief FileElementCollectionItem::localName
* @return the located name of this item
*/
QString FileElementCollectionItem::localName()
{
if (!text().isNull())
@@ -120,12 +120,17 @@ QString FileElementCollectionItem::localName()
else if (isDir()) {
if (isCollectionRoot()) {
QString macrosPath = QETApp::userMacrosDir();
if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1);
if (m_path == QETApp::commonElementsDirN())
setText(QObject::tr("Collection QET"));
else if (m_path == QETApp::companyElementsDirN())
setText(QObject::tr("Collection Company"));
else if (m_path == QETApp::customElementsDirN())
setText(QObject::tr("Collection utilisateur"));
else if (m_path == macrosPath)
setText(QObject::tr("Makros"));
else
setText(QObject::tr("Collection inconnue"));
}
@@ -136,7 +141,7 @@ QString FileElementCollectionItem::localName()
if(docu.load_file(str.toStdString().c_str()))
{
if (QString(docu.document_element().name())
== "qet-directory")
== "qet-directory")
{
NamesList nl;
nl.fromXml(docu.document_element());
@@ -147,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();
@@ -169,7 +178,11 @@ QString FileElementCollectionItem::localName(const ElementsLocation &location)
localName();
}
else if (isElement()) {
setText(location.name());
QString display_name = location.name();
if (display_name.endsWith(".qetmak")) {
display_name.remove(".qetmak");
}
setText(display_name);
}
return text();
@@ -194,24 +207,29 @@ QString FileElementCollectionItem::name() const
QString FileElementCollectionItem::collectionPath() const
{
if (isCollectionRoot()) {
QString macrosPath = QETApp::userMacrosDir();
if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1);
if (m_path == QETApp::commonElementsDirN())
return "common://";
else if (m_path == QETApp::companyElementsDirN())
return "company://";
else
return "custom://";
else if (m_path == macrosPath)
return "macros://"; //
else
return "custom://";
}
else if (parent() && parent()->type()
== FileElementCollectionItem::Type) {
== FileElementCollectionItem::Type) {
ElementCollectionItem *eci =
static_cast<ElementCollectionItem*>(parent());
if (eci->isCollectionRoot())
return eci->collectionPath() + m_path;
static_cast<ElementCollectionItem*>(parent());
if (eci->isCollectionRoot())
return eci->collectionPath() + m_path;
else
return eci->collectionPath() % "/" % m_path;
}
else
return QString();
}
else
return QString();
}
/**
@@ -220,10 +238,14 @@ QString FileElementCollectionItem::collectionPath() const
*/
bool FileElementCollectionItem::isCollectionRoot() const
{
QString macrosPath = QETApp::userMacrosDir();
if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1);
if (m_path == QETApp::commonElementsDirN()
|| m_path == QETApp::companyElementsDirN()
|| m_path == QETApp::customElementsDirN())
return true;
|| m_path == QETApp::companyElementsDirN()
|| m_path == QETApp::customElementsDirN()
|| m_path == macrosPath)
return true;
else
return false;
}
@@ -273,55 +295,63 @@ void FileElementCollectionItem::addChildAtPath(const QString &collection_name)
}
/**
@brief FileElementCollectionItem::setUpData
SetUp the data of this item
*/
* @brief FileElementCollectionItem::setUpData
* SetUp the data of this item
*/
void FileElementCollectionItem::setUpData()
{
if (isDir())
{
localName();
setFlags(Qt::ItemIsSelectable
| Qt::ItemIsDragEnabled
| Qt::ItemIsDropEnabled
| Qt::ItemIsEnabled);
| Qt::ItemIsDragEnabled
| Qt::ItemIsDropEnabled
| Qt::ItemIsEnabled);
}
else
{
setFlags(Qt::ItemIsSelectable
| Qt::ItemIsDragEnabled
| Qt::ItemIsEnabled);
//Set the local name and all informations of the element
//in the data Qt::UserRole+1, these data will be use for search.
ElementsLocation loc(collectionPath());
DiagramContext context = loc.elementInformations();
QStringList search_list;
for (QString& key : context.keys())
{ search_list.append(context.value(key).toString()); }
search_list.append(localName(loc));
setData(search_list.join(" "));
| Qt::ItemIsDragEnabled
| Qt::ItemIsEnabled);
if (m_path.endsWith(".qetmak")) {
setData(localName());
} else {
// Parse standard element information for search
ElementsLocation loc(collectionPath());
DiagramContext context = loc.elementInformations();
QStringList search_list;
for (QString& key : context.keys())
{ search_list.append(context.value(key).toString()); }
search_list.append(localName(loc));
setData(search_list.join(" "));
}
}
setToolTip(collectionPath());
}
/**
@brief FileElementCollectionItem::setUpIcon
SetUp the icon of this item.
Because icon use several memory,
we use this method for setup icon instead setUpData.
*/
* @brief FileElementCollectionItem::setUpIcon
* SetUp the icon of this item.
* Because icon use several memory,
* we use this method for setup icon instead setUpData.
*/
void FileElementCollectionItem::setUpIcon()
{
if (!icon().isNull())
return;
if (isCollectionRoot()) {
QString macrosPath = QETApp::userMacrosDir();
if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1);
if (m_path == QETApp::commonElementsDirN())
setIcon(QIcon(":/ico/16x16/qet.png"));
else if (m_path == QETApp::companyElementsDirN())
setIcon(QIcon(":/ico/16x16/go-company.png"));
else if (m_path == macrosPath)
setIcon(QIcon(":/ico/16x16/go-home.png"));
else
setIcon(QIcon(":/ico/16x16/go-home.png"));
}
@@ -330,8 +360,12 @@ void FileElementCollectionItem::setUpIcon()
if (isDir()) {
setIcon(QET::Icons::Folder);
} else {
ElementsLocation loc(collectionPath());
setIcon(loc.icon());
if (m_path.endsWith(".qetmak")) {
setIcon(QIcon());
} else {
ElementsLocation loc(collectionPath());
setIcon(loc.icon());
}
}
}
}
@@ -347,13 +381,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);
}
@@ -382,9 +416,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);
@@ -393,3 +427,15 @@ void FileElementCollectionItem::populate(bool set_data, bool hide_element)
feci->setUpData();
}
}
/**
* @brief FileElementCollectionItem::isMacrosCollection
* @return True if this item represent the macros collection
*/
bool FileElementCollectionItem::isMacrosCollection() const
{
QString macrosPath = QETApp::userMacrosDir();
if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1);
return fileSystemPath().startsWith(macrosPath);
}

View File

@@ -50,6 +50,7 @@ class FileElementCollectionItem : public ElementCollectionItem
bool isCommonCollection() const;
bool isCompanyCollection() const;
bool isCustomCollection() const;
bool isMacrosCollection() const;
void addChildAtPath(const QString &collection_name) override;
void setUpData() override;

View File

@@ -58,6 +58,10 @@ XmlElementCollection::XmlElementCollection(QETProject *project) :
QChar(0x30A4), QChar(0x30F3), QChar(0x30D0), QChar(0x30FC),
QChar(0x30C8), QChar(0x3055), QChar(0x308C), QChar(0x305F),
QChar(0x8981), QChar(0x7D20)};
const QChar korean_data[8] = {
QChar(0xC804), QChar(0xAE30), QChar(0x0020),
QChar(0xC2EC), QChar(0xBCFC), QChar(0x0020),
QChar(0xC694), QChar(0xC18C)};
const QChar russian_data[24] = {
QChar(0x0418), QChar(0x043C), QChar(0x043F), QChar(0x043E),
QChar(0x0440), QChar(0x0442), QChar(0x0438), QChar(0x0440),
@@ -88,6 +92,8 @@ XmlElementCollection::XmlElementCollection(QETProject *project) :
names.addName("it", "Elementi importati");
names.addName("ja", QString(japanese_data, 10));
//names.addName("ja", "インバートされた要素");
names.addName("ko", QString(korean_data, 8));
names.addName("ko_KR", QString(korean_data, 8));
names.addName("nl", "Elementen geïmporteerd");
names.addName("nl_BE", "Elementen geïmporteerd");
names.addName("pl", "Elementy importowane");