Commit 9baf784b authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Merge remote-tracking branch 'origin/release/19.12'

parents 320e15cf 28fad5c3
......@@ -449,6 +449,8 @@ void WidgetBasePopupMenu::insertSingleSelectionMenu(WidgetBase* widget)
}
insert(mt_Delete);
insert(mt_Change_Font);
if (type == WidgetBase::wt_Precondition)
insert(mt_Properties);
break;
case WidgetBase::wt_CombinedFragment:
......@@ -469,6 +471,7 @@ void WidgetBasePopupMenu::insertSingleSelectionMenu(WidgetBase* widget)
insert(mt_Rename, i18n("Change Text..."));
insert(mt_Delete);
insert(mt_Change_Font);
insert(mt_Properties);
break;
case WidgetBase::wt_Text:
......
......@@ -40,7 +40,8 @@ ToolBarState::~ToolBarState()
*/
void ToolBarState::init()
{
m_pUMLScene->activeView()->viewport()->setMouseTracking(false);
if (m_pUMLScene->activeView())
m_pUMLScene->activeView()->viewport()->setMouseTracking(false);
m_pMouseEvent = 0;
m_currentWidget = 0;
m_currentAssociation = 0;
......
......@@ -451,6 +451,10 @@ void CombinedFragmentWidget::slotMenuSelection(QAction* action)
}
break;
case ListPopupMenu::mt_Properties:
showPropertiesDialog();
break;
default:
UMLWidget::slotMenuSelection(action);
}
......
......@@ -57,7 +57,8 @@ PreconditionWidget::PreconditionWidget(UMLScene* scene, ObjectWidget* a, Uml::ID
else
m_nY = y();
activate();
connect(m_objectWidget, SIGNAL(sigWidgetMoved(Uml::ID::Type)), this, SLOT(slotWidgetMoved(Uml::ID::Type)));
calculateDimensions();
}
/**
......@@ -78,19 +79,21 @@ void PreconditionWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem
int w = width();
int h = height();
int x = m_objectWidget->x() + m_objectWidget->width() / 2;
x -= w/2;
setX(x);
int y = this->y();
//test if y isn't above the object
if (y <= m_objectWidget->y() + m_objectWidget->height()) {
y = m_objectWidget->y() + m_objectWidget->height() + 15;
}
if (y + h >= m_objectWidget->getEndLineY()) {
y = m_objectWidget->getEndLineY() - h;
if (m_objectWidget) {
int x = m_objectWidget->x() + m_objectWidget->width() / 2;
x -= w/2;
setX(x);
int y = this->y();
//test if y isn't above the object
if (y <= m_objectWidget->y() + m_objectWidget->height()) {
y = m_objectWidget->y() + m_objectWidget->height() + 15;
}
if (y + h >= m_objectWidget->getEndLineY()) {
y = m_objectWidget->getEndLineY() - h;
}
setY(y);
}
setY(y);
setPenFromSettings(painter);
if (UMLWidget::useFillColor()) {
painter->setBrush(UMLWidget::fillColor());
......@@ -152,16 +155,17 @@ bool PreconditionWidget::activate(IDChangeLog * Log /*= 0*/)
m_scene->resetPastePoint();
UMLWidget::activate(Log);
loadObjectWidget();
if (!m_objectWidget) {
DEBUG(DBG_SRC) << "role A widget " << Uml::ID::toString(m_widgetAId)
<< " could not be found";
return false;
if (m_objectWidget == nullptr &&
!(m_widgetAId.empty() || m_widgetAId == Uml::ID::None || m_widgetAId == Uml::ID::Reserved)) {
UMLWidget *w = umlScene()->findWidget(m_widgetAId);
m_objectWidget = w->asObjectWidget();
if (!m_objectWidget) {
DEBUG(DBG_SRC) << "role A widget " << Uml::ID::toString(m_widgetAId) << " could not be found";
return false;
}
connect(m_objectWidget, SIGNAL(sigWidgetMoved(Uml::ID::Type)), this, SLOT(slotWidgetMoved(Uml::ID::Type)));
}
connect(m_objectWidget, SIGNAL(sigWidgetMoved(Uml::ID::Type)), this, SLOT(slotWidgetMoved(Uml::ID::Type)));
calculateDimensions();
return true;
}
......@@ -170,8 +174,10 @@ bool PreconditionWidget::activate(IDChangeLog * Log /*= 0*/)
* Resolve references of this precondition so it references the correct
* new object widget after paste.
*/
void PreconditionWidget::resolveObjectWidget(IDChangeLog* log) {
void PreconditionWidget::resolveObjectWidget(IDChangeLog* log)
{
m_widgetAId = log->findNewID(m_widgetAId);
activate(log);
}
/**
......@@ -182,18 +188,17 @@ void PreconditionWidget::calculateDimensions()
int x = 0;
int w = 0;
int h = 0;
int x1 = m_objectWidget->x();
int w1 = m_objectWidget->width() / 2;
x1 += w1;
QSizeF q = minimumSize();
w = q.width() > width() ? q.width() : width();
h = q.height() > height() ? q.height() : height();
x = x1 - w/2;
m_nPosX = x;
if (m_objectWidget) {
int x1 = m_objectWidget->x();
int w1 = m_objectWidget->width() / 2;
x1 += w1;
x = x1 - w/2;
m_nPosX = x;
}
setSize(w, h);
}
......@@ -203,7 +208,7 @@ void PreconditionWidget::calculateDimensions()
*/
void PreconditionWidget::slotWidgetMoved(Uml::ID::Type id)
{
const Uml::ID::Type idA = m_objectWidget->localID();
const Uml::ID::Type idA = m_objectWidget ? m_objectWidget->localID() : Uml::ID::None;
if (idA != id) {
DEBUG(DBG_SRC) << "id=" << Uml::ID::toString(id) << ": ignoring for idA=" << Uml::ID::toString(idA);
return;
......@@ -263,6 +268,10 @@ void PreconditionWidget::slotMenuSelection(QAction* action)
}
break;
case ListPopupMenu::mt_Properties:
showPropertiesDialog();
break;
default:
UMLWidget::slotMenuSelection(action);
}
......@@ -289,31 +298,19 @@ bool PreconditionWidget::loadFromXMI1(QDomElement& qElement)
{
if(!UMLWidget::loadFromXMI1(qElement))
return false;
QString widgetaid = qElement.attribute(QLatin1String("widgetaid"), QLatin1String("-1"));
setName(qElement.attribute(QLatin1String("preconditionname")));
setDocumentation(qElement.attribute(QLatin1String("documentation")));
QString widgetaid = qElement.attribute(QLatin1String("widgetaid"), QLatin1String("-1"));
m_widgetAId = Uml::ID::fromString(widgetaid);
// Lookup the ObjectWidget, if it can't be found, assume it will be
// resolved later
loadObjectWidget();
return true;
}
/**
* Load the object widget from m_widgetAId
*
* This method is called in loadFromXMI1() when loading an XMI file, and called
* from activate() when activating a widget after pasting.
*/
void PreconditionWidget::loadObjectWidget()
ObjectWidget *PreconditionWidget::objectWidget() const
{
if (m_objectWidget == 0) {
m_objectWidget = dynamic_cast<ObjectWidget*>(
umlScene()->findWidget(m_widgetAId)
);
}
return m_objectWidget;
}
void PreconditionWidget::setObjectWidget(ObjectWidget *objectWidget)
{
m_objectWidget = objectWidget;
}
......@@ -47,7 +47,8 @@ public:
virtual void saveToXMI1(QDomDocument& qDoc, QDomElement& qElement);
virtual bool loadFromXMI1(QDomElement& qElement);
void setObjectWidget(ObjectWidget* widget);
ObjectWidget *objectWidget() const;
void setObjectWidget(ObjectWidget *objectWidget);
public slots:
void slotMenuSelection(QAction* action);
......@@ -64,7 +65,6 @@ private:
int m_nY;
Uml::ID::Type m_widgetAId;
void loadObjectWidget();
};
#endif
......@@ -131,6 +131,13 @@ ecm_add_test(
TEST_NAME testumlcanvasobject
)
ecm_add_test(
testpreconditionwidget.cpp
testbase.cpp
LINK_LIBRARIES ${LIBS}
TEST_NAME testpreconditionwidget
)
set(testumlroledialog_SRCS
testumlroledialog.cpp
)
......
......@@ -181,4 +181,48 @@ UMLObject *TestUML<T,N>::secondary() const
return T::m_pSecondary.data();
}
/**
* template for adding test save/load support to widget related classes
*/
template <class T, typename N>
class TestWidget : public T
{
public:
TestWidget<T,N>(UMLScene *scene, N w) : T(scene, w) {}
QDomDocument testSave1();
bool testLoad1(QDomDocument &qDoc);
void testDump(const QString &title = QString());
};
template <class T, typename N>
QDomDocument TestWidget<T,N>::testSave1()
{
QDomDocument qDoc;
QDomElement root = qDoc.createElement("unittest");
qDoc.appendChild(root);
T::saveToXMI1(qDoc, root);
return qDoc;
}
template <class T, typename N>
bool TestWidget<T,N>::testLoad1(QDomDocument &qDoc)
{
QDomElement root = qDoc.childNodes().at(0).toElement();
QDomElement e = root.childNodes().at(0).toElement();
bool result = T::loadFromXMI1(e);
if (result) {
const SignalBlocker sb(UMLApp::app()->document());
result = T::activate(nullptr);
}
return result;
}
template <class T, typename N>
void TestWidget<T,N>::testDump(const QString &title)
{
QDomDocument doc = testSave1();
QString xml = doc.toString();
qDebug() << title << doc.toString();
}
#endif // TESTBASE_H
/*
Copyright 2019 Ralf Habacker <ralf.habacker@freenet.de>
This program 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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "testpreconditionwidget.h"
#include "preconditionwidget.h"
#include "folder.h"
#include "objectwidget.h"
#include "umlscene.h"
typedef TestWidget<PreconditionWidget, ObjectWidget*> TestPreconditionWidgetClass;
void TestPreconditionWidget::test_saveAndLoad()
{
UMLFolder folder("testfolder");
UMLScene scene(&folder);
UMLObject o(nullptr);
ObjectWidget ow(&scene, &o);
scene.addWidgetCmd(&ow);
TestPreconditionWidgetClass pw1(&scene, &ow);
scene.addWidgetCmd(&pw1);
QDomDocument save = pw1.testSave1();
//pw1.testDump("save");
TestPreconditionWidgetClass pw2(&scene, nullptr);
QCOMPARE(pw2.testLoad1(save), true);
QCOMPARE(pw2.testSave1().toString(), save.toString());
//pw2.testDump("load");
QCOMPARE(pw2.objectWidget(), &ow);
}
QTEST_MAIN(TestPreconditionWidget)
/*
Copyright 2019 Ralf Habacker <ralf.habacker@freenet.de>
This program 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) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TESTPRECONDITIONWIDGET_H
#define TESTPRECONDITIONWIDGET_H
#include "testbase.h"
class TestPreconditionWidget : public TestBase
{
Q_OBJECT
private slots:
void test_saveAndLoad();
};
#endif // TESTPRECONDITIONWIDGET_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment