diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index 40fb89482e..4badc264ac 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -60,7 +60,7 @@ class PropertyModel; See also: https://man42.net/blog/2011/09/qt-4-7-modify-a-custom-q_property-with-a-qt-style-sheet/ */ -class PropertyEditor: public QTreeView +class GuiExport PropertyEditor: public QTreeView { // clang-format off Q_OBJECT diff --git a/src/Gui/propertyeditor/PropertyModel.h b/src/Gui/propertyeditor/PropertyModel.h index 34c4620312..0a6288f3c9 100644 --- a/src/Gui/propertyeditor/PropertyModel.h +++ b/src/Gui/propertyeditor/PropertyModel.h @@ -38,7 +38,7 @@ class Property; namespace Gui { namespace PropertyEditor { -class PropertyModel : public QAbstractItemModel +class GuiExport PropertyModel : public QAbstractItemModel { Q_OBJECT diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 83ebaf38c7..d11cc682be 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -34,7 +34,6 @@ qt_create_resource_file(${TechDraw_TR_QRC} ${QM_SRCS}) qt_add_resources(TechDrawGui_SRCS Resources/TechDraw.qrc ${TechDraw_TR_QRC}) set(TechDrawGui_UIC_SRCS - DlgStringListEditor.ui DlgPageChooser.ui DlgPrefsTechDrawAdvanced.ui DlgPrefsTechDrawAnnotation.ui @@ -110,9 +109,6 @@ SET(TechDrawGui_SRCS TaskProjGroup.ui TaskProjGroup.cpp TaskProjGroup.h - DlgStringListEditor.ui - DlgStringListEditor.cpp - DlgStringListEditor.h DlgPageChooser.ui DlgPageChooser.cpp DlgPageChooser.h diff --git a/src/Mod/TechDraw/Gui/DlgStringListEditor.cpp b/src/Mod/TechDraw/Gui/DlgStringListEditor.cpp deleted file mode 100644 index 5a0efc28d2..0000000000 --- a/src/Mod/TechDraw/Gui/DlgStringListEditor.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** - * Copyright (c) 2022 Wanderer Fan * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ****************************************************************************/ - -#include "PreCompiled.h" -#ifndef _PreComp_ -# include -#endif - -#include "DlgStringListEditor.h" -#include "ui_DlgStringListEditor.h" - - -using namespace TechDrawGui; - -/* TRANSLATOR Gui::DlgStringListEditor */ - -DlgStringListEditor::DlgStringListEditor(const std::vector texts, QWidget* parent, - Qt::WindowFlags fl) - : QDialog(parent, fl), - ui(new Ui_DlgStringListEditor) -{ - ui->setupUi(this); - ui->lwTexts->setSortingEnabled(false); - - fillList(texts); - - connect(ui->lwTexts, - &QListWidget::itemActivated, - this, - &DlgStringListEditor::slotItemActivated); - connect(ui->pbAdd, &QPushButton::clicked, this, &DlgStringListEditor::slotAddItem); - connect(ui->pbRemove, &QPushButton::clicked, this, &DlgStringListEditor::slotRemoveItem); - connect(ui->bbButtons, &QDialogButtonBox::accepted, this, &DlgStringListEditor::accept); - connect(ui->bbButtons, &QDialogButtonBox::rejected, this, &DlgStringListEditor::reject); -} - -/** - * Destroys the object and frees any allocated resources - */ -DlgStringListEditor::~DlgStringListEditor() -{ - // no need to delete child widgets, Qt does it all for us - delete ui; -} - -void DlgStringListEditor::fillList(std::vector texts) -{ - QString qText; - int textCount = texts.size(); - int i = 0; - for (; i < textCount; i++) { - qText = QString::fromStdString(texts[i]); - QListWidgetItem* item = new QListWidgetItem(qText); - item->setFlags(item->flags() | Qt::ItemIsEditable); - ui->lwTexts->addItem(item); - } - //add a blank line at the end to allow extending the list - QListWidgetItem* item = new QListWidgetItem(QStringLiteral("")); - item->setFlags(item->flags() | Qt::ItemIsEditable); - ui->lwTexts->addItem(item); -} - -void DlgStringListEditor::slotItemActivated(QListWidgetItem* item) -{ - ui->lwTexts->editItem(item); -} - -void DlgStringListEditor::slotAddItem() -{ - QString newText = ui->leNewItem->text(); - QListWidgetItem* item = new QListWidgetItem(newText); - item->setFlags(item->flags() | Qt::ItemIsEditable); - int row = ui->lwTexts->currentRow(); - if (row < 0) { - //no location set yet, add to end of list - ui->lwTexts->addItem(item); - } - else { - //insert item at current row and push the rest down 1 position - ui->lwTexts->insertItem(row, item); - } - ui->leNewItem->clear(); - //TODO: how to append to end of list? -} - -void DlgStringListEditor::slotRemoveItem() -{ - if (ui->lwTexts->count() < 1) { - return; - } - int row = ui->lwTexts->currentRow(); - if (row >= 0) { - auto item = ui->lwTexts->takeItem(row); - delete item; - } -} - -std::vector DlgStringListEditor::getTexts() const -{ - std::vector outTexts; - if (ui->lwTexts->count() < 1) { - return outTexts; - } - - for (int iRow = 0; iRow < ui->lwTexts->count(); iRow++) { - QString itemText = ui->lwTexts->item(iRow)->text(); - outTexts.push_back(itemText.toStdString()); - } - if (outTexts.back().empty()) { - outTexts.pop_back(); - } - return outTexts; -} - -void DlgStringListEditor::accept() -{ - QDialog::accept(); -} - -void DlgStringListEditor::reject() -{ - QDialog::reject(); -} - -#include "moc_DlgStringListEditor.cpp" diff --git a/src/Mod/TechDraw/Gui/DlgStringListEditor.h b/src/Mod/TechDraw/Gui/DlgStringListEditor.h deleted file mode 100644 index b8a28c2e06..0000000000 --- a/src/Mod/TechDraw/Gui/DlgStringListEditor.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * Copyright (c) 2022 Wanderer Fan * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ****************************************************************************/ - -#ifndef GUI_DLGEDITABLETEXT_H -#define GUI_DLGEDITABLETEXT_H - -#include - -#include - - -class QListWidgetItem; - -namespace TechDrawGui { - -class Ui_DlgStringListEditor; -class TechDrawGuiExport DlgStringListEditor : public QDialog -{ - Q_OBJECT - -public: - DlgStringListEditor(const std::vector texts, - QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags()); - ~DlgStringListEditor() override; - - std::vector getTexts() const; - void accept() override; - void reject() override; - -public Q_SLOTS: - void slotItemActivated(QListWidgetItem* item); - void slotAddItem(); - void slotRemoveItem(); - -private: - void fillList(std::vector texts); - - Ui_DlgStringListEditor* ui; -}; - -} // namespace Gui - - -#endif // GUI_DLGEDITABLETEXT_H - diff --git a/src/Mod/TechDraw/Gui/DlgStringListEditor.ui b/src/Mod/TechDraw/Gui/DlgStringListEditor.ui deleted file mode 100644 index 43076bbc58..0000000000 --- a/src/Mod/TechDraw/Gui/DlgStringListEditor.ui +++ /dev/null @@ -1,140 +0,0 @@ - - - TechDrawGui::DlgStringListEditor - - - Qt::WindowModal - - - - 0 - 0 - 360 - 331 - - - - String List Editor - - - - - - true - - - - - - - - <html><head/><body><p>Double click to edit a line. New lines are added at the current location in the list.</p></body></html> - - - QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked - - - true - - - - - - - - - - :/icons/list-add.svg - - - - - - - - - - - - - - - - - - - :/icons/list-remove.svg:/icons/list-remove.svg - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - false - - - - - - - - - - - - bbButtons - accepted() - TechDrawGui::DlgStringListEditor - accept() - - - 179 - 228 - - - 179 - 139 - - - - - bbButtons - rejected() - TechDrawGui::DlgStringListEditor - reject() - - - 179 - 228 - - - 179 - 139 - - - - - diff --git a/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp b/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp index 363e4aa1c5..e1df9385e9 100644 --- a/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp @@ -37,6 +37,7 @@ #include #endif +#include "ViewProviderAnnotation.h" #include #include #include @@ -45,7 +46,6 @@ #include #include -#include "DlgStringListEditor.h" #include "QGCustomText.h" #include "QGIViewAnnotation.h" #include "Rez.h" @@ -181,20 +181,18 @@ void QGIViewAnnotation::rotateView() void QGIViewAnnotation::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) { - Q_UNUSED(event); - + // forwards the double click on the page to the view provider, as of the item in the tree was + // double clicked, just like the QGILeaderLine TechDraw::DrawViewAnnotation* annotation = dynamic_cast(getViewObject()); if (!annotation) { return; } - - const std::vector& values = annotation->Text.getValues(); - DlgStringListEditor dlg(values, Gui::getMainWindow()); - dlg.setWindowTitle(QStringLiteral("Annotation Text Editor")); - if (dlg.exec() == QDialog::Accepted) { - App::GetApplication().setActiveTransaction("Set Annotation Text"); - annotation->Text.setValues(dlg.getTexts()); - App::GetApplication().closeActiveTransaction(); + auto ViewProvider = dynamic_cast(getViewProvider(annotation)); + if (!ViewProvider) { + qWarning() << "QGIViewAnnotation::mouseDoubleClickEvent: No valid view provider"; + return; } + ViewProvider->startDefaultEditMode(); + QGraphicsItem::mouseDoubleClickEvent(event); } diff --git a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp index 9d05f13b7a..54b0db7975 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.cpp @@ -22,8 +22,15 @@ ***************************************************************************/ #include "PreCompiled.h" +#ifndef _PreComp_ +#include +#endif #include +#include +#include +#include +#include #include #include @@ -87,3 +94,51 @@ TechDraw::DrawViewAnnotation* ViewProviderAnnotation::getViewObject() const { return dynamic_cast(pcObject); } + +bool ViewProviderAnnotation::doubleClicked() +{ + setEdit(ViewProvider::Default); + return true; +} + +bool ViewProviderAnnotation::setEdit(int ModNum) +{ + if (ModNum != ViewProvider::Default) { + return ViewProviderDrawingView::setEdit(ModNum); + } + // retrieves the PropertyEditor of the Data tab in the comboview of the + // mainwindow and opens the editor of the "text" property of the selected + // item and mimics a click of the button inside that editor, which opens + // the plain text edit dialog + // I feel quite dirty writing this but that was the cleanest way to prevent + // code duplication, because everything just works as long as the structure + // does not change. In case this modus operandi gets used more + // often, this should be delegated to a utility function that takes a property + // path and opens the "deepest" editor of that property + auto comboView = qobject_cast( + Gui::DockWindowManager::instance()->getDockWindow("Model")); + if (!comboView) { + return false; + } + auto dataPropView = comboView->findChild( + QStringLiteral("propertyEditorData")); + if (!dataPropView) { + return false; + } + auto dataPropModel = qobject_cast(dataPropView->model()); + if (!dataPropModel) { + return false; + } + // the property data is a tree model, to we need the first item in the first group + auto index = dataPropModel->propertyIndexFromPath( + {QStringLiteral("Annotation"), QStringLiteral("Text")}); + // setting the current item also opens the editor + dataPropView->setCurrentIndex(index); + dataPropView->activated(index); + // there is a button in the editor wigdet that opens a plain text dialog + auto button = dataPropView->findChild(); + if (button) { + button->click(); + } + return true; +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h index b32402c6f6..4bdba5ccc4 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h +++ b/src/Mod/TechDraw/Gui/ViewProviderAnnotation.h @@ -51,6 +51,9 @@ public: std::vector claimChildren(void) const override; TechDraw::DrawViewAnnotation* getViewObject() const override; + + bool doubleClicked() override; + bool setEdit(int ModNum) override; }; }// namespace TechDrawGui