[Uml-devel] branches/work/soc-umbrello/umbrello
Andi Fischer
andi.fischer at hispeed.ch
Sat Oct 17 12:05:50 UTC 2009
SVN commit 1036548 by fischer:
Moving some static functions from umlscene to the new widgetlist_utils.
M +1 -0 CMakeLists.txt
M +25 -202 umlscene.cpp
M +4 -29 umlscene.h
M +4 -11 umlwidgetlist.h
M +23 -2 widgets/widget_utils.cpp
M +2 -8 widgets/widget_utils.h
A widgets/widgetlist_utils.cpp [License: GPL (v2+)]
A widgets/widgetlist_utils.h [License: GPL (v2+)]
--- branches/work/soc-umbrello/umbrello/CMakeLists.txt #1036547:1036548
@@ -339,6 +339,7 @@
widgets/widget_utils.cpp
widgets/widgetbase.cpp
widgets/widgethandle.cpp
+ widgets/widgetlist_utils.cpp
)
set (libcontroller_SRCS
--- branches/work/soc-umbrello/umbrello/umlscene.cpp #1036547:1036548
@@ -12,10 +12,10 @@
#include "umlscene.h"
// system includes
-#include <climits>
-#include <math.h>
+#include <cmath> // for ceil
// include files for Qt
+#include <QtAlgorithms> // for qSort
#include <QtGui/QPainter>
#include <QtGui/QPrinter>
#include <QtGui/QPixmap>
@@ -32,7 +32,6 @@
#include <kdebug.h>
// application specific includes
-
#include "activitywidget.h"
#include "actorwidget.h"
#include "artifactwidget.h"
@@ -44,13 +43,13 @@
#include "boxwidget.h"
#include "classifier.h"
#include "classifierwidget.h"
-#include "clipboard/idchangelog.h"
-#include "clipboard/umldragdata.h"
+#include "idchangelog.h"
+#include "umldragdata.h"
#include "cmds.h"
#include "componentwidget.h"
#include "datatypewidget.h"
-#include "dialogs/classoptionspage.h"
-#include "dialogs/umlviewdialog.h"
+#include "classoptionspage.h"
+#include "umlviewdialog.h"
#include "docwindow.h"
#include "entity.h"
#include "entitywidget.h"
@@ -88,6 +87,9 @@
#include "uniqueid.h"
#include "usecasewidget.h"
#include "widget_factory.h"
+#include "widget_utils.h"
+#include "widgetlist_utils.h"
+
#define TEST 1
#include "test.h"
@@ -3927,7 +3929,7 @@
if (widgetList.isEmpty())
return;
- qreal smallestX = getSmallestX(widgetList);
+ qreal smallestX = WidgetList_Utils::getSmallestX(widgetList);
foreach(UMLWidget *widget , widgetList) {
widget->setPos(smallestX, widget->pos().y());
@@ -3944,7 +3946,7 @@
getSelectedWidgets(widgetList);
if (widgetList.isEmpty())
return;
- qreal biggestX = getBiggestX(widgetList);
+ qreal biggestX = WidgetList_Utils::getBiggestX(widgetList);
foreach(UMLWidget *widget , widgetList) {
widget->setPos(biggestX - widget->width(), widget->pos().y());
@@ -3962,7 +3964,7 @@
if (widgetList.isEmpty())
return;
- qreal smallestY = getSmallestY(widgetList);
+ qreal smallestY = WidgetList_Utils::getSmallestY(widgetList);
foreach(UMLWidget *widget , widgetList) {
widget->setPos(widget->pos().x(), smallestY);
@@ -3979,7 +3981,7 @@
getSelectedWidgets(widgetList);
if (widgetList.isEmpty())
return;
- qreal biggestY = getBiggestY(widgetList);
+ qreal biggestY = WidgetList_Utils::getBiggestY(widgetList);
foreach(UMLWidget *widget , widgetList) {
widget->setPos(widget->pos().x(), biggestY - widget->height());
@@ -3997,8 +3999,8 @@
if (widgetList.isEmpty())
return;
- qreal smallestX = getSmallestX(widgetList);
- qreal biggestX = getBiggestX(widgetList);
+ qreal smallestX = WidgetList_Utils::getSmallestX(widgetList);
+ qreal biggestX = WidgetList_Utils::getBiggestX(widgetList);
qreal middle = int((biggestX - smallestX) / 2) + smallestX;
foreach(UMLWidget *widget , widgetList) {
@@ -4017,8 +4019,8 @@
if (widgetList.isEmpty())
return;
- qreal smallestY = getSmallestY(widgetList);
- qreal biggestY = getBiggestY(widgetList);
+ qreal smallestY = WidgetList_Utils::getSmallestY(widgetList);
+ qreal biggestY = WidgetList_Utils::getBiggestY(widgetList);
qreal middle = int((biggestY - smallestY) / 2) + smallestY;
foreach(UMLWidget *widget , widgetList) {
@@ -4037,12 +4039,12 @@
if (widgetList.isEmpty())
return;
- qreal smallestY = getSmallestY(widgetList);
- qreal biggestY = getBiggestY(widgetList);
- qreal heightsSum = getHeightsSum(widgetList);
+ qreal smallestY = WidgetList_Utils::getSmallestY(widgetList);
+ qreal biggestY = WidgetList_Utils::getBiggestY(widgetList);
+ qreal heightsSum = WidgetList_Utils::getHeightsSum(widgetList);
qreal distance = int(((biggestY - smallestY) - heightsSum) / (widgetList.count() - 1.0) + 0.5);
- sortWidgetList(widgetList, hasWidgetSmallerY);
+ qSort(widgetList.begin(), widgetList.end(), Widget_Utils::hasSmallerY);
int i = 1;
UMLWidget* widgetPrev = NULL;
@@ -4068,12 +4070,12 @@
if (widgetList.isEmpty())
return;
- qreal smallestX = getSmallestX(widgetList);
- qreal biggestX = getBiggestX(widgetList);
- qreal widthsSum = getWidthsSum(widgetList);
+ qreal smallestX = WidgetList_Utils::getSmallestX(widgetList);
+ qreal biggestX = WidgetList_Utils::getBiggestX(widgetList);
+ qreal widthsSum = WidgetList_Utils::getWidthsSum(widgetList);
qreal distance = int(((biggestX - smallestX) - widthsSum) / (widgetList.count() - 1.0) + 0.5);
- sortWidgetList(widgetList, hasWidgetSmallerX);
+ qSort(widgetList.begin(), widgetList.end(), Widget_Utils::hasSmallerX);
int i = 1;
UMLWidget* widgetPrev = NULL;
@@ -4091,185 +4093,6 @@
}
-/**
- * Returns true if the first widget's X is smaller than second's.
- * Used for sorting the UMLWidgetList.
- *
- * @param widget1 The widget to compare.
- * @param widget2 The widget to compare with.
- */
-bool UMLScene::hasWidgetSmallerX(const UMLWidget* widget1, const UMLWidget* widget2)
-{
- return widget1->x() < widget2->x();
-}
-
-/**
- * Returns true if the first widget's Y is smaller than second's.
- * Used for sorting the UMLWidgetList.
- *
- * @param widget1 The widget to compare.
- * @param widget2 The widget to compare with.
- */
-bool UMLScene::hasWidgetSmallerY(const UMLWidget* widget1, const UMLWidget* widget2)
-{
- return widget1->y() < widget2->y();
-}
-
-/**
- * Looks for the smallest x-value of the given UMLWidgets.
- *
- * @param widgetList A list with UMLWidgets.
- */
-qreal UMLScene::getSmallestX(const UMLWidgetList &widgetList)
-{
- UMLWidgetListIt it(widgetList);
-
- qreal smallestX = 0;
-
- int i = 1;
- foreach(UMLWidget *widget , widgetList) {
- if (i == 1) {
- smallestX = widget->x();
- } else {
- if (smallestX > widget->x())
- smallestX = widget->x();
- }
- i++;
- }
-
- return smallestX;
-}
-
-/**
- * Looks for the smallest y-value of the given UMLWidgets.
- *
- * @param widgetList A list with UMLWidgets.
- */
-qreal UMLScene::getSmallestY(const UMLWidgetList &widgetList)
-{
- if (widgetList.isEmpty())
- return -1;
-
- qreal smallestY = 0;
-
- int i = 1;
- foreach(UMLWidget *widget , widgetList) {
- if (i == 1) {
- smallestY = widget->y();
- } else {
- if (smallestY > widget->y())
- smallestY = widget->y();
- }
- i++;
- }
-
- return smallestY;
-}
-
-/**
- * Looks for the biggest x-value of the given UMLWidgets.
- *
- * @param widgetList A list with UMLWidgets.
- */
-qreal UMLScene::getBiggestX(const UMLWidgetList &widgetList)
-{
- if (widgetList.isEmpty())
- return -1;
-
- qreal biggestX = 0;
-
- int i = 1;
- foreach(UMLWidget *widget , widgetList) {
- if (i == 1) {
- biggestX = widget->x();
- biggestX += widget->width();
- } else {
- if (biggestX < widget->x() + widget->width())
- biggestX = widget->x() + widget->width();
- }
- i++;
- }
-
- return biggestX;
-}
-
-/**
- * Looks for the biggest y-value of the given UMLWidgets.
- *
- * @param widgetList A list with UMLWidgets.
- */
-qreal UMLScene::getBiggestY(const UMLWidgetList &widgetList)
-{
- if (widgetList.isEmpty())
- return -1;
-
- qreal biggestY = 0;
-
- int i = 1;
- foreach(UMLWidget *widget , widgetList) {
- if (i == 1) {
- biggestY = widget->y();
- biggestY += widget->height();
- } else {
- if (biggestY < widget->y() + widget->height())
- biggestY = widget->y() + widget->height();
- }
- i++;
- }
-
- return biggestY;
-}
-
-/**
- * Returns the sum of the heights of the given UMLWidgets
- *
- * @param widgetList A list with UMLWidgets.
- */
-qreal UMLScene::getHeightsSum(const UMLWidgetList &widgetList)
-{
- qreal heightsSum = 0;
-
-
- foreach(UMLWidget *widget , widgetList) {
- heightsSum += widget->height();
- }
-
- return heightsSum;
-}
-
-/**
- * Returns the sum of the widths of the given UMLWidgets.
- *
- * @param widgetList A list with UMLWidgets.
- */
-qreal UMLScene::getWidthsSum(const UMLWidgetList &widgetList)
-{
- qreal widthsSum = 0;
-
- foreach(UMLWidget *widget , widgetList) {
- widthsSum += widget->width();
- }
-
- return widthsSum;
-}
-
-template<typename Compare>
-void UMLScene::sortWidgetList(UMLWidgetList &widgetList, Compare comp)
-{
- QVector<UMLWidget*> widgetVector;
-
- for (UMLWidgetList::iterator it = widgetList.begin(); it != widgetList.end(); ++it) {
- widgetVector.push_back(*it);
- }
- qSort(widgetVector.begin(), widgetVector.end(), comp);
-
- widgetList.clear();
-
- for (QVector<UMLWidget*>::iterator it = widgetVector.begin(); it != widgetVector.end(); ++it) {
- widgetList.append(*it);
- }
-}
-
void UMLScene::test()
{
#ifdef TEST
--- branches/work/soc-umbrello/umbrello/umlscene.h #1036547:1036548
@@ -11,7 +11,7 @@
#ifndef UMLSCENE_H
#define UMLSCENE_H
-//local includes
+// local includes
#include "umlnamespace.h"
#include "optionstate.h"
#include "umlobjectlist.h"
@@ -25,11 +25,14 @@
#include <QtXml/QDomDocument>
// forward declarations
+class QPrinter;
class ClassOptionsPage;
class IDChangeLog;
class ListPopupMenu;
class FloatingTextWidget;
class ObjectWidget;
+class ToolBarState;
+class ToolBarStateFactory;
class UMLFolder;
class UMLApp;
class UMLDoc;
@@ -41,10 +44,6 @@
class UMLEntity;
class UMLView;
-class QPrinter;
-class ToolBarState;
-class ToolBarStateFactory;
-
/**
* UMLScene instances represent diagrams.
* The UMLScene class inherits from QGraphicsScene.
@@ -689,30 +688,6 @@
UMLForeignKeyConstraint* fkConstraint,
UMLWidget* widget);
- static bool hasWidgetSmallerX(const UMLWidget* widget1, const UMLWidget* widget2);
- static bool hasWidgetSmallerY(const UMLWidget* widget1, const UMLWidget* widget2);
-
- qreal getSmallestX(const UMLWidgetList &widgetList);
- qreal getSmallestY(const UMLWidgetList &widgetList);
- qreal getBiggestX(const UMLWidgetList &widgetList);
- qreal getBiggestY(const UMLWidgetList &widgetList);
- qreal getHeightsSum(const UMLWidgetList &widgetList);
- qreal getWidthsSum(const UMLWidgetList &widgetList);
-
- /**
- * Sorts the given UMLWidgetList based on the Compare function.
- * The list is cleared and all the widgets are added again in order.
- *
- * The comp function gets two const UMLWidget* params and returns
- * a boolean telling if the first widget was smaller than the second,
- * whatever the "smaller" concept is depending on the sorting to do.
- *
- * @param widgetList The list with the widgets to order.
- * @param comp The comp function to compare the widgets.
- */
- template<typename Compare>
- void sortWidgetList(UMLWidgetList &widgetList, Compare comp);
-
public slots:
void slotToolBarChanged(int c);
void slotObjectCreated(UMLObject * o);
--- branches/work/soc-umbrello/umbrello/umlwidgetlist.h #1036547:1036548
@@ -1,25 +1,18 @@
/***************************************************************************
- umlwidgetlist.h - description
- -------------------
- begin : Sat Dec 29 2001
- copyright : (C) 2001 by Gustavo Madrigal
- email : gmadrigal at nextphere.com
- Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
- ***************************************************************************/
-
-/***************************************************************************
- * *
* 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) any later version. *
* *
+ * copyright (C) 2001 Gustavo Madrigal <gmadrigal at nextphere.com> *
+ * copyright (C) 2004-2009 *
+ * Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
***************************************************************************/
#ifndef UMLWIDGETLIST_H
#define UMLWIDGETLIST_H
-#include <qlist.h>
+#include <QtCore/QList>
class UMLWidget;
--- branches/work/soc-umbrello/umbrello/widgets/widget_utils.cpp #1036547:1036548
@@ -18,7 +18,7 @@
#include "umlview.h"
#include "umlwidget.h"
-// qt/kde includes
+// qt includes
#include <QtCore/QBuffer>
#include <QtGui/QBrush>
#include <QtGui/QImageReader>
@@ -237,7 +237,6 @@
painter->drawPath(path);
}
-
/**
* Converts a point to a comma separated string i.e "x,y"
*/
@@ -529,4 +528,26 @@
qElement.appendChild(brushElement);
}
+ /**
+ * Returns true if the first widget's X is smaller than second's.
+ * Used for sorting the UMLWidgetList.
+ * @param widget1 The widget to compare.
+ * @param widget2 The widget to compare with.
+ */
+ bool hasSmallerX(const UMLWidget* widget1, const UMLWidget* widget2)
+ {
+ return widget1->x() < widget2->x();
+ }
+
+ /**
+ * Returns true if the first widget's Y is smaller than second's.
+ * Used for sorting the UMLWidgetList.
+ * @param widget1 The widget to compare.
+ * @param widget2 The widget to compare with.
+ */
+ bool hasSmallerY(const UMLWidget* widget1, const UMLWidget* widget2)
+ {
+ return widget1->y() < widget2->y();
+ }
+
} // namespace Widget_Utils
--- branches/work/soc-umbrello/umbrello/widgets/widget_utils.h #1036547:1036548
@@ -30,7 +30,6 @@
*/
namespace Widget_Utils
{
-
UMLWidget* findWidget(Uml::IDType id,
const UMLWidgetList& widgets,
const MessageWidgetList* messages = 0);
@@ -38,33 +37,28 @@
QGraphicsRectItem *decoratePoint(const QPointF& p);
void drawCrossInEllipse(QPainter *p, const QRectF& ellipse);
-
void drawTriangledRect(QPainter *painter, const QRectF& rect, const QSizeF& triSize);
-
void drawArrowHead(QPainter *painter, const QPointF& arrowPos,
const QSizeF& arrowSize, Qt::ArrowType arrowType,
bool solid = false);
-
void drawRoundedRect(QPainter *painter, const QRectF& rect, qreal xRadius,
qreal yRadius, Uml::Corners corners);
QString pointToString(const QPointF& point);
-
QPointF stringToPoint(const QString& str);
bool loadPixmapFromXMI(QDomElement &qElement, QPixmap &pixmap);
-
void savePixmapToXMI(QDomDocument &qDoc, QDomElement &qElement, const QPixmap& pixmap);
bool loadGradientFromXMI(QDomElement &qElement, QGradient *&gradient);
-
void saveGradientToXMI(QDomDocument &qDoc, QDomElement &qElement, const QGradient *gradient);
bool loadBrushFromXMI(QDomElement &qElement, QBrush &brush);
-
void saveBrushToXMI(QDomDocument &qDoc, QDomElement &qElement,
const QBrush& brush);
+ bool hasSmallerX(const UMLWidget* widget1, const UMLWidget* widget2);
+ bool hasSmallerY(const UMLWidget* widget1, const UMLWidget* widget2);
}
#endif
More information about the umbrello-devel
mailing list