TechDraw: Replace annotation edit dialog with QPlainTextEdit (#20092)
* TechDraw: Replace annotation edit dialog with QPlainTextEdit * Remove useless include introduced in previous commit * Remove trailing _ for members to conform with rest of the codebase * Add const & to string vectors that don't need copying * Fix IWYU linter warnings * Forward all annotation double clicks to the StringList property editor * Remove unused dialog * Fix Qt 5 build error * Fix missing exports with MSVC
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* 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 <QListWidgetItem>
|
||||
#endif
|
||||
|
||||
#include "DlgStringListEditor.h"
|
||||
#include "ui_DlgStringListEditor.h"
|
||||
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
/* TRANSLATOR Gui::DlgStringListEditor */
|
||||
|
||||
DlgStringListEditor::DlgStringListEditor(const std::vector<std::string> 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<std::string> 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<std::string> DlgStringListEditor::getTexts() const
|
||||
{
|
||||
std::vector<std::string> 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"
|
||||
@@ -1,64 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* 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 <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
class QListWidgetItem;
|
||||
|
||||
namespace TechDrawGui {
|
||||
|
||||
class Ui_DlgStringListEditor;
|
||||
class TechDrawGuiExport DlgStringListEditor : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DlgStringListEditor(const std::vector<std::string> texts,
|
||||
QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags());
|
||||
~DlgStringListEditor() override;
|
||||
|
||||
std::vector<std::string> getTexts() const;
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotItemActivated(QListWidgetItem* item);
|
||||
void slotAddItem();
|
||||
void slotRemoveItem();
|
||||
|
||||
private:
|
||||
void fillList(std::vector<std::string> texts);
|
||||
|
||||
Ui_DlgStringListEditor* ui;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
|
||||
#endif // GUI_DLGEDITABLETEXT_H
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TechDrawGui::DlgStringListEditor</class>
|
||||
<widget class="QDialog" name="TechDrawGui::DlgStringListEditor">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::WindowModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>360</width>
|
||||
<height>331</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>String List Editor</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="lwTexts">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Double click to edit a line. New lines are added at the current location in the list.</p></body></html></string>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbAdd">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/list-add.svg</normalon>
|
||||
</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="leNewItem"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbRemove">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../Gui/Icons/resource.qrc">
|
||||
<normaloff>:/icons/list-remove.svg</normaloff>:/icons/list-remove.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="bbButtons">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="Resources/TechDraw.qrc"/>
|
||||
<include location="../../../Gui/Icons/resource.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>bbButtons</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>TechDrawGui::DlgStringListEditor</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>179</x>
|
||||
<y>228</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>179</x>
|
||||
<y>139</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>bbButtons</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>TechDrawGui::DlgStringListEditor</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>179</x>
|
||||
<y>228</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>179</x>
|
||||
<y>139</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <QVBoxLayout>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderAnnotation.h"
|
||||
#include <App/Application.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools.h>
|
||||
@@ -45,7 +46,6 @@
|
||||
#include <Mod/TechDraw/App/DrawViewAnnotation.h>
|
||||
#include <Mod/TechDraw/App/Preferences.h>
|
||||
|
||||
#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<TechDraw::DrawViewAnnotation*>(getViewObject());
|
||||
if (!annotation) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& 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<ViewProviderAnnotation*>(getViewProvider(annotation));
|
||||
if (!ViewProvider) {
|
||||
qWarning() << "QGIViewAnnotation::mouseDoubleClickEvent: No valid view provider";
|
||||
return;
|
||||
}
|
||||
ViewProvider->startDefaultEditMode();
|
||||
QGraphicsItem::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,15 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <QPushButton>
|
||||
#endif
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Gui/ComboView.h>
|
||||
#include <Gui/DockWindowManager.h>
|
||||
#include <Gui/propertyeditor/PropertyEditor.h>
|
||||
#include <Gui/propertyeditor/PropertyModel.h>
|
||||
#include <Mod/TechDraw/App/DrawLeaderLine.h>
|
||||
#include <Mod/TechDraw/App/DrawViewBalloon.h>
|
||||
|
||||
@@ -87,3 +94,51 @@ TechDraw::DrawViewAnnotation* ViewProviderAnnotation::getViewObject() const
|
||||
{
|
||||
return dynamic_cast<TechDraw::DrawViewAnnotation*>(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::DockWnd::ComboView*>(
|
||||
Gui::DockWindowManager::instance()->getDockWindow("Model"));
|
||||
if (!comboView) {
|
||||
return false;
|
||||
}
|
||||
auto dataPropView = comboView->findChild<Gui::PropertyEditor::PropertyEditor*>(
|
||||
QStringLiteral("propertyEditorData"));
|
||||
if (!dataPropView) {
|
||||
return false;
|
||||
}
|
||||
auto dataPropModel = qobject_cast<Gui::PropertyEditor::PropertyModel*>(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<QPushButton*>();
|
||||
if (button) {
|
||||
button->click();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ public:
|
||||
std::vector<App::DocumentObject*> claimChildren(void) const override;
|
||||
|
||||
TechDraw::DrawViewAnnotation* getViewObject() const override;
|
||||
|
||||
bool doubleClicked() override;
|
||||
bool setEdit(int ModNum) override;
|
||||
};
|
||||
|
||||
}// namespace TechDrawGui
|
||||
|
||||
Reference in New Issue
Block a user