[Uml-devel] branches/work/soc-umbrello/umbrello
Andi Fischer
andi.fischer at hispeed.ch
Sun Nov 11 09:02:03 UTC 2012
SVN commit 1324833 by fischer:
debug_utils changes from trunk applied.
M +7 -5 association.cpp
M +71 -31 debug/debug_utils.cpp
M +42 -9 debug/debug_utils.h
U dialogs/assocpage.cpp
M +2 -2 dialogs/codeeditor.cpp
M +2 -2 uml.cpp
M +2 -1 umlcanvasobject.cpp
M +2 -1 umldoc.cpp
M +2 -2 umllistview.cpp
M +2 -1 umllistviewitem.cpp
M +2 -0 umlobject.cpp
M +2 -2 umlscene.cpp
M +1 -2 umlscene.h
M +3 -2 umlview.cpp
M +2 -1 umlviewimageexportermodel.cpp
M +2 -2 widgets/layoutgrid.cpp
--- branches/work/soc-umbrello/umbrello/association.cpp #1324832:1324833
@@ -30,6 +30,8 @@
using namespace Uml;
+DEBUG_REGISTER(UMLAssociation)
+
/**
* Sets up an association.
* A new unique ID is assigned internally.
@@ -237,7 +239,7 @@
if (m_pUMLPackage == NULL) {
Uml::ModelType mt = Model_Utils::convert_OT_MT(obj[r]->baseType());
m_pUMLPackage = doc->rootFolder(mt);
- uDebug() << "assoctype " << m_AssocType
+ DEBUG(DBG_SRC) << "assoctype " << m_AssocType
<< ": setting model type " << mt;
}
}
@@ -340,7 +342,7 @@
if (m_pUMLPackage == NULL) {
Uml::ModelType mt = Model_Utils::convert_OT_MT(getObject(B)->baseType());
m_pUMLPackage = doc->rootFolder(mt);
- uDebug() << "setting model type " << mt;
+ DEBUG(DBG_SRC) << "setting model type " << mt;
}
// setting the association type:
@@ -392,7 +394,7 @@
"relationship" // Uml::AssociationType::Relationship
};
const int arraySize = sizeof(assocTypeString)/sizeof(QString);
- uDebug() << "AssociationType string array size = " << arraySize;
+ DEBUG(DBG_SRC) << "AssociationType string array size = " << arraySize;
int index;
for (index = 0; index < arraySize; ++index)
@@ -493,7 +495,7 @@
uError() << "role " << role << ": getObject returns NULL";
return Uml::id_None;
} else {
- uDebug() << "role " << role << ": using secondary ID " << auxID;
+ DEBUG(DBG_SRC) << "role " << role << ": using secondary ID " << auxID;
return STR2ID(auxID);
}
}
@@ -592,7 +594,7 @@
// In this case we need to auto-set the multiplicity/rolenames
// of the roles
#ifdef VERBOSE_DEBUGGING
- uDebug() << " A new uni-association has been created.";
+ DEBUG(DBG_SRC) << " A new uni-association has been created.";
#endif
}
UMLObject::emitModified();
--- branches/work/soc-umbrello/umbrello/debug/debug_utils.cpp #1324832:1324833
@@ -1,5 +1,6 @@
/*
Copyright 2011 Andi Fischer <andi.fischer at hispeed.ch>
+ Copyright 2012 Ralf Habacker <ralf.habacker at 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
@@ -23,7 +24,9 @@
#include <klocale.h>
Tracer* Tracer::m_instance = 0;
+QMap<QString,bool> *Tracer::m_classes = 0;
+
Tracer* Tracer::instance()
{
if (m_instance == 0) {
@@ -39,11 +42,15 @@
Tracer::Tracer(QWidget *parent)
: QTreeWidget(parent)
{
+ // in case no one called registerClass() before
+ if (!m_classes)
+ m_classes = new QMap<QString,bool>;
setRootIsDecorated(true);
setAlternatingRowColors(true);
setHeaderLabel(i18n("Class Name"));
setContextMenuPolicy(Qt::CustomContextMenu);
resize(300, 400);
+ connect(this,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(slotItemClicked(QTreeWidgetItem*,int)));
}
/**
@@ -52,42 +59,37 @@
Tracer::~Tracer()
{
clear();
+ delete m_classes;
}
/**
- * ... .
+ * Return debugging state for a given class
+ * @param name the class name to check
*/
-void Tracer::registerClass(const QString& name, const QString& folder)
+bool Tracer::isEnabled(const QString& name)
{
- QList<QTreeWidgetItem*> items = findItems(name, Qt::MatchFixedString);
- if (items.empty()) {
- uDebug() << name << " / folder = " << folder;
- QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(name));
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- item->setCheckState(0, Qt::Checked);
- addTopLevelItem(item);
+ return (*m_classes)[name];
}
-}
/**
- * ...
- * @param name the class name for which the debug messages are enabled
+ * Enable debug output for the given class.
+ * @param name class name
*/
void Tracer::enable(const QString& name)
{
- QList<QTreeWidgetItem*> items = findItems(name, Qt::MatchFixedString);
- foreach(QTreeWidgetItem* item, items) {
- item->setCheckState(0, Qt::Checked);
+ (*m_classes)[name] = true;
+ update(name);
}
-}
+/**
+ * Disable debug output for the given class.
+ * @param name class name
+ */
void Tracer::disable(const QString& name)
{
- QList<QTreeWidgetItem*> items = findItems(name, Qt::MatchFixedString);
- foreach(QTreeWidgetItem* item, items) {
- item->setCheckState(0, Qt::Unchecked);
+ (*m_classes)[name] = false;
+ update(name);
}
-}
void Tracer::enableAll()
{
@@ -99,20 +101,58 @@
//:TODO:
}
-bool Tracer::isEnabled(const QString& name)
+/**
+ * Register class for debug output
+ * @param name class name
+ * @param state initial enabled state
+ */
+void Tracer::registerClass(const QString& name, bool state)
{
+ if (!m_classes)
+ m_classes = new QMap<QString,bool>;
+ (*m_classes)[name] = state;
+}
+
+/**
+ * Transfer class state into tree widget.
+ * @param name class name
+ */
+void Tracer::update(const QString &name)
+{
+ if (!isVisible())
+ return;
QList<QTreeWidgetItem*> items = findItems(name, Qt::MatchFixedString);
- if (items.size() > 0) {
- Qt::CheckState state = items.at(0)->checkState(0);
- switch(state) {
- case Qt::Checked:
- return true;
- case Qt::Unchecked:
- default:
- return false;
+ foreach(QTreeWidgetItem* item, items) {
+ item->setCheckState(0, (*m_classes)[name] ? Qt::Checked : Qt::Unchecked);
}
}
- return false;
+
+/**
+ * Fill tree widget with collected classes.
+ */
+void Tracer::showEvent(QShowEvent* e)
+{
+ Q_UNUSED(e);
+
+ clear();
+ QMapIterator<QString, bool> i(*m_classes);
+ while (i.hasNext()) {
+ i.next();
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(i.key()));
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ item->setCheckState(0, i.value() ? Qt::Checked : Qt::Unchecked);
+ addTopLevelItem(item);
}
+}
-#include "debug_utils.moc"
+/**
+ * handle tree widget item selection signal
+ * @param item tree widget item
+ * @param column selected column
+ */
+void Tracer::slotItemClicked(QTreeWidgetItem* item, int colum)
+{
+ Q_UNUSED(colum);
+
+ (*m_classes)[item->text(0)] = !(*m_classes)[item->text(0)];
+}
--- branches/work/soc-umbrello/umbrello/debug/debug_utils.h #1324832:1324833
@@ -1,5 +1,6 @@
/*
Copyright 2011 Andi Fischer <andi.fischer at hispeed.ch>
+ Copyright 2012 Ralf Habacker <ralf.habacker at 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
@@ -26,7 +27,35 @@
/**
* @short The singleton class for switching on or off debug messages.
*
- * This class ... .
+ * This class provides a user controllable way to enable class related
+ * debug output.
+ *
+ * Classes could be registered with the static method registerClass().
+ *
+ * With show() a dialog will be shown, in which the user is able to
+ * enable/disable debug output for each registered class.
+ *
+ * Class related debug output implementation
+ *
+ * To register classes independent from related object instantiation time
+ * one of the macros
+ *
+ * DEBUG_REGISTER(className)
+ * DEBUG_REGISTER_DISABLED(className)
+ *
+ * should be placed in the implementation part of a class before the
+ * first class methods. The first macro enables debug output for the
+ * related class, while the latter macro disables it by default.
+ *
+ * Debug output in class methods should use
+ *
+ * - QObject based classes
+ *
+ * DEBUG(DBG_SRC) << ...
+ *
+ * - other classes
+ *
+ * DEBUG("class name") << ...
*/
class Tracer : public QTreeWidget
{
@@ -36,24 +65,29 @@
~Tracer();
- void registerClass(const QString& name, const QString& folder = QString());
-
+ bool isEnabled(const QString& name);
void enable(const QString& name);
void disable(const QString& name);
void enableAll();
void disableAll();
- bool isEnabled(const QString& name);
+ static void registerClass(const QString& name, bool state=true);
+protected:
+ void update(const QString &name);
+ virtual void showEvent(QShowEvent* );
+
+private slots:
+ void slotItemClicked(QTreeWidgetItem* item, int colum);
+
private:
static Tracer* m_instance;
+ static QMap<QString,bool> *m_classes;
explicit Tracer(QWidget *parent = 0);
-
};
-
#include <kdebug.h>
// convenience macros for console output to the Umbrello area
@@ -62,12 +96,11 @@
#define uWarning() kWarning(8060)
#define DBG_SRC QString(metaObject()->className())
-#define DEBUG_REGISTER(src) Tracer::instance()->registerClass(src);
-#define DEBUG_REGISTER_DISABLED(src) Tracer::instance()->registerClass(src); Tracer::instance()->disable(src);
#define DEBUG_SHOW_FILTER() Tracer::instance()->show()
#define DEBUG(src) if (Tracer::instance()->isEnabled(src)) uDebug()
+#define DEBUG_REGISTER(src) class src##Tracer { public: src##Tracer() { Tracer::registerClass(#src, true); } }; static src##Tracer src##TracerGlobal;
+#define DEBUG_REGISTER_DISABLED(src) class src##Tracer { public: src##Tracer() { Tracer::registerClass(#src, false); } }; static src##Tracer src##TracerGlobal;
-
#define uIgnoreZeroPointer(a) if (!a) { uDebug() << "zero pointer detected" << __FILE__ << __LINE__; continue; }
--- branches/work/soc-umbrello/umbrello/dialogs/codeeditor.cpp #1324832:1324833
@@ -52,6 +52,8 @@
#include <QPointer>
#include <QRegExp>
+DEBUG_REGISTER(CodeEditor)
+
/**
* Constructor.
*/
@@ -933,8 +935,6 @@
*/
void CodeEditor::init(CodeViewerDialog * parentDlg, CodeDocument * parentDoc)
{
- DEBUG_REGISTER(DBG_SRC);
-
// safety to insure that we are up to date
parentDoc->synchronize();
--- branches/work/soc-umbrello/umbrello/uml.cpp #1324832:1324833
@@ -115,6 +115,8 @@
return NULL;
}
+DEBUG_REGISTER(UMLApp)
+
/**
* Constructor. Calls all init functions to create the application.
*/
@@ -160,8 +162,6 @@
initClip();
readOptions();
- DEBUG_REGISTER(DBG_SRC);
-
//get a reference to the Code->Active Language and to the Diagram->Zoom menu
m_langSelect = findMenu(QString("active_lang_menu") );
//in case langSelect hasn't been initialized we create the Popup menu.
--- branches/work/soc-umbrello/umbrello/umlcanvasobject.cpp #1324832:1324833
@@ -26,6 +26,8 @@
// kde includes
#include <klocale.h>
+DEBUG_REGISTER_DISABLED(UMLCanvasObject)
+
/**
* Sets up a UMLCanvasObject.
*
@@ -35,7 +37,6 @@
UMLCanvasObject::UMLCanvasObject(const QString & name, Uml::IDType id)
: UMLObject(name, id)
{
- DEBUG_REGISTER_DISABLED(DBG_SRC);
}
/**
--- branches/work/soc-umbrello/umbrello/umldoc.cpp #1324832:1324833
@@ -71,6 +71,8 @@
// Update this version when changing the XMI file format
#define XMI_FILE_VERSION "1.6.1"
+DEBUG_REGISTER(UMLDoc)
+
/**
* Constructor for the fileclass of the application.
*/
@@ -92,7 +94,6 @@
m_pCurrentRoot(0),
m_bClosing(false)
{
- DEBUG_REGISTER(DBG_SRC);
}
/**
--- branches/work/soc-umbrello/umbrello/umllistview.cpp #1324832:1324833
@@ -74,6 +74,8 @@
#include <QRect>
#include <QToolTip>
+DEBUG_REGISTER(UMLListView)
+
/**
* Constructs the tree view.
*
@@ -115,8 +117,6 @@
m_lv[i] = 0;
}
- DEBUG_REGISTER(DBG_SRC);
-
//setup slots/signals
connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(slotCollapsed(QTreeWidgetItem*)));
connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(slotExpanded(QTreeWidgetItem*)));
--- branches/work/soc-umbrello/umbrello/umllistviewitem.cpp #1324832:1324833
@@ -45,6 +45,8 @@
#define DBG_LVI "UMLListViewItem"
+DEBUG_REGISTER(UMLListViewItem)
+
/**
* Sets up an instance.
*
@@ -190,7 +192,6 @@
m_bCreating = false;
m_object = 0;
m_id = Uml::id_None;
- DEBUG_REGISTER(DBG_LVI);
}
/**
--- branches/work/soc-umbrello/umbrello/umlobject.cpp #1324832:1324833
@@ -36,6 +36,8 @@
using namespace Uml;
+DEBUG_REGISTER_DISABLED(UMLObject)
+
/**
* Creates a UMLObject.
* @param parent The parent of the object.
--- branches/work/soc-umbrello/umbrello/umlscene.cpp #1324832:1324833
@@ -94,6 +94,8 @@
using namespace Uml;
+DEBUG_REGISTER(UMLScene)
+
/**
* Constructor.
*/
@@ -143,8 +145,6 @@
setBackgroundBrush(QColor(195, 195, 195));
m_layoutGrid = new LayoutGrid();
addItem(m_layoutGrid);
-
- DEBUG_REGISTER(DBG_SRC);
}
/**
--- branches/work/soc-umbrello/umbrello/umlscene.h #1324832:1324833
@@ -65,6 +65,7 @@
typedef QSizeF UMLSceneSize;
typedef QLineF UMLSceneLine;
typedef qreal UMLSceneValue;
+
// event types
typedef QGraphicsSceneHoverEvent UMLSceneHoverEvent;
typedef QGraphicsSceneContextMenuEvent UMLSceneContextMenuEvent;
@@ -72,8 +73,6 @@
typedef QGraphicsSceneDragDropEvent UMLSceneDragEnterEvent;
typedef QGraphicsSceneDragDropEvent UMLSceneDragMoveEvent;
-typedef QGraphicsEllipseItem UMLSceneEllipse;
-
/**
* UMLScene instances represent diagrams.
* The UMLScene class inherits from QGraphicsScene and it owns the
--- branches/work/soc-umbrello/umbrello/umlview.cpp #1324832:1324833
@@ -11,6 +11,7 @@
// own header
#include "umlview.h"
+// application specific includes
#include "debug_utils.h"
#include "docwindow.h"
#include "uml.h"
@@ -20,6 +21,8 @@
#include <QMouseEvent>
+DEBUG_REGISTER(UMLView)
+
/**
* Constructor
*/
@@ -35,8 +38,6 @@
UMLScene *scene = new UMLScene(parentFolder);
setScene(scene);
setSceneRect(scene->sceneRect());
-
- DEBUG_REGISTER(DBG_SRC);
}
/**
--- branches/work/soc-umbrello/umbrello/umlviewimageexportermodel.cpp #1324832:1324833
@@ -42,6 +42,8 @@
#define DBG_IEM "UMLViewImageExporterModel"
+DEBUG_REGISTER(UMLViewImageExporterModel)
+
QStringList UMLViewImageExporterModel::s_supportedImageTypesList;
QStringList UMLViewImageExporterModel::s_supportedMimeTypesList;
@@ -148,7 +150,6 @@
*/
UMLViewImageExporterModel::UMLViewImageExporterModel()
{
- DEBUG_REGISTER(DBG_IEM);
}
/**
--- branches/work/soc-umbrello/umbrello/widgets/layoutgrid.cpp #1324832:1324833
@@ -26,6 +26,8 @@
#include <QPainter>
#include <QTextStream>
+DEBUG_REGISTER_DISABLED(LayoutGrid)
+
/**
* Constructor.
*/
@@ -41,8 +43,6 @@
m_isVisible(false),
m_isTextVisible(false)
{
- DEBUG_REGISTER_DISABLED("LayoutGrid");
-
m_coordLabel = new QGraphicsTextItem(QString("0, 0"), this);
}
More information about the umbrello-devel
mailing list