Commit d02e8a7e authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Add dock window showing all uml objects for further debugging.

parent 37ba24a2
......@@ -235,6 +235,7 @@ endmacro(add_unstable_feature)
add_unstable_feature(WIDGET_SHOW_DOC) # show documentation in classes ticket xxx
add_unstable_feature(NEW_CODE_GENERATORS) # new c++ code generator
add_unstable_feature(UML_OBJECTS_WINDOW) # objects dock window
if(LIBXSLT_FOUND AND LIBXML2_FOUND)
add_subdirectory(umbrello)
......
......@@ -439,6 +439,7 @@ set(umbrellobase_SRCS
birdview.cpp
cmdlineexportallviewsevent.cpp
diagramswindow.cpp
objectswindow.cpp
docwindow.cpp
dotgenerator.cpp
icon_utils.cpp
......@@ -475,6 +476,7 @@ set(umbrellobase_SRCS
set(umbrellomodels_SRCS
models/diagramsmodel.cpp
models/objectsmodel.cpp
models/stereotypesmodel.cpp
)
......
/***************************************************************************
* 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) 2016 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#include "objectsmodel.h"
// app includes
#include "attribute.h"
#include "folder.h"
#include "operation.h"
#include "uml.h"
#include "umldoc.h"
// kde includes
#include <KLocalizedString>
// qt includes
#include <QtDebug>
ObjectsModel::ObjectsModel()
{
}
bool ObjectsModel::add(UMLObject *o)
{
if (m_allObjects.contains(o))
return false;
int index = m_allObjects.size();
beginInsertRows(QModelIndex(), index, index);
m_allObjects.append(o);
endInsertRows();
return true;
}
bool ObjectsModel::remove(UMLObject *o)
{
int index = m_allObjects.indexOf(o);
if (index == -1)
return false;
beginRemoveRows(QModelIndex(), index, index);
m_allObjects.removeAll(o);
endRemoveRows();
return true;
}
int ObjectsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
int count = m_allObjects.size();
return count;
}
int ObjectsModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 4;
}
QVariant ObjectsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (section < 0)
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Vertical)
return section + 1;
if (section == 0)
return QVariant(i18n("Name"));
else if (section == 1)
return QVariant(i18n("Type"));
else if (section == 2)
return QVariant(i18n("Folder"));
else if (section == 3)
return QVariant(i18n("ID"));
else return QVariant();
}
QVariant ObjectsModel::data(const QModelIndex & index, int role) const
{
if (role == Qt::UserRole && index.column() == 0) {
QVariant v;
v.setValue(m_allObjects.at(index.row()).data());
return v;
}
else if (role != Qt::DisplayRole)
return QVariant();
int cCount = columnCount(index);
if (index.column() >= cCount)
return QVariant();
UMLObject *o = m_allObjects.at(index.row());
if (index.column() == 0)
return o->name();
else if (index.column() == 1)
return o->baseTypeStr();
else if (index.column() == 2) {
QVariant v;
if (o->umlPackage())
v.setValue(o->umlPackage()->name());
else if (o->parent()) {
UMLObject *p = dynamic_cast<UMLObject*>(o->parent());
if (p)
v.setValue(p->name());
}
return v;
} else if (index.column() == 3)
return Uml::ID::toString(o->id());
return QVariant();
}
void ObjectsModel::emitDataChanged(const QModelIndex &index)
{
emit dataChanged(index, index);
}
void ObjectsModel::emitDataChanged(int index)
{
QModelIndex mi = createIndex(index,0);
emit dataChanged(mi, mi);
}
void ObjectsModel::emitDataChanged(UMLObject *o)
{
#if QT_VERSION < 0x050000
emit layoutAboutToBeChanged();
#endif
int index = m_allObjects.indexOf(o);
emitDataChanged(index);
#if QT_VERSION < 0x050000
emit layoutChanged();
#endif
}
/***************************************************************************
* 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) 2016 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#ifndef OBJECTSMODEL_H
#define OBJECTSMODEL_H
// qt includes
#include <QAbstractTableModel>
#include <QPointer>
class UMLObject;
Q_DECLARE_METATYPE(UMLObject*);
class ObjectsModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit ObjectsModel();
bool add(UMLObject *o);
bool remove(UMLObject *o);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
void emitDataChanged(const QModelIndex &index);
void emitDataChanged(int index);
void emitDataChanged(UMLObject *o);
protected:
QList<QPointer<UMLObject>> m_allObjects;
};
#endif // OBJECTSMODEL_H
/***************************************************************************
* 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) 2016 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#include "objectswindow.h"
// app includes
#include "models/objectsmodel.h"
#include "uml.h"
#include "umldoc.h"
#include "umlview.h"
// kde includes
#include <KLocalizedString>
// qt includes
#include <QHeaderView>
#include <QTableView>
#include <QSortFilterProxyModel>
#include <QtDebug>
ObjectsWindow::ObjectsWindow(const QString &title, QWidget *parent)
: QDockWidget(title, parent)
{
setObjectName(QLatin1String("ObjectsWindow"));
QSortFilterProxyModel *proxy = new QSortFilterProxyModel;
proxy->setSourceModel(UMLApp::app()->document()->objectsModel());
proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
m_objectsTree = new QTableView;
m_objectsTree->setModel(proxy);
m_objectsTree->setSortingEnabled(true);
m_objectsTree->verticalHeader()->setDefaultSectionSize(20);
m_objectsTree->verticalHeader()->setVisible(false);
#if QT_VERSION >= 0x050000
m_diagramsTree->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else
m_objectsTree->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
#endif
setWidget(m_objectsTree);
connect(m_objectsTree, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotObjectsDoubleClicked(QModelIndex)));
connect(m_objectsTree, SIGNAL(clicked(QModelIndex)), this, SLOT(slotObjectsClicked(QModelIndex)));
}
ObjectsWindow::~ObjectsWindow()
{
delete m_objectsTree;
}
void ObjectsWindow::modified()
{
UMLObject *o = dynamic_cast<UMLObject*>(QObject::sender());
if (!o)
return;
UMLApp::app()->document()->objectsModel()->emitDataChanged(o);
}
void ObjectsWindow::slotObjectsDoubleClicked(QModelIndex index)
{
QVariant v = m_objectsTree->model()->data(index, Qt::UserRole);
if (v.canConvert<UMLObject*>()) {
UMLObject *o = v.value<UMLObject*>();
o->showPropertiesDialog(this);
}
}
void ObjectsWindow::slotObjectsClicked(QModelIndex index)
{
#if 1
Q_UNUSED(index)
#else
QVariant v = m_objectsTree->model()->data(index, Qt::UserRole);
if (v.canConvert<UMLObject*>()) {
UMLObject *o = v.value<UMLObject*>();
//o->showPropertiesDialog(this);
}
#endif
}
/***************************************************************************
* 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) 2016 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#ifndef ObjectsWindow_H
#define ObjectsWindow_H
#include <QDockWidget>
#include <QModelIndex>
class QTableView;
class ObjectsWindow : public QDockWidget
{
Q_OBJECT
public:
explicit ObjectsWindow(const QString &title, QWidget *parent = 0);
~ObjectsWindow();
signals:
public slots:
void modified();
protected slots:
void slotObjectsDoubleClicked(QModelIndex index);
void slotObjectsClicked(QModelIndex index);
protected:
QTableView *m_objectsTree;
};
#endif // ObjectsWindow_H
......@@ -932,6 +932,9 @@ void UMLApp::initView()
setCentralWidget(widget);
m_d->createDiagramsWindow();
#ifdef ENABLE_UML_OBJECTS_WINDOW
m_d->createObjectsWindow();
#endif
m_d->createStereotypesWindow();
// create the tree viewer
......
......@@ -16,6 +16,7 @@
#include "findresults.h"
#include "uml.h"
#include "diagramswindow.h"
#include "objectswindow.h"
#include "stereotypeswindow.h"
// kde includes
......@@ -52,8 +53,10 @@ public:
FindResults findResults;
QListWidget *logWindow; ///< Logging window.
KToggleAction *viewDiagramsWindow;
KToggleAction *viewObjectsWindow;
KToggleAction *viewStereotypesWindow;
DiagramsWindow *diagramsWindow;
ObjectsWindow *objectsWindow;
StereotypesWindow *stereotypesWindow;
KTextEditor::Editor *editor;
......@@ -125,6 +128,16 @@ public slots:
connect(viewDiagramsWindow, SIGNAL(triggered(bool)), diagramsWindow, SLOT(setVisible(bool)));
}
void createObjectsWindow()
{
// create the object window
objectsWindow = new ObjectsWindow(i18n("&UML Objects"), parent);
parent->addDockWidget(Qt::RightDockWidgetArea, objectsWindow);
viewObjectsWindow = parent->actionCollection()->add<KToggleAction>(QLatin1String("view_objects_window"));
connect(viewObjectsWindow, SIGNAL(triggered(bool)), objectsWindow, SLOT(setVisible(bool)));
}
void createStereotypesWindow()
{
// create the tree viewer
......
......@@ -45,6 +45,7 @@
#include "version.h"
#include "worktoolbar.h"
#include "models/diagramsmodel.h"
#include "models/objectsmodel.h"
#include "models/stereotypesmodel.h"
// kde includes
......@@ -117,6 +118,7 @@ UMLDoc::UMLDoc()
m_pCurrentRoot(0),
m_bClosing(false),
m_diagramsModel(new DiagramsModel),
m_objectsModel(new ObjectsModel),
m_stereotypesModel(new StereotypesModel(&m_stereoList))
{
for (int i = 0; i < Uml::ModelType::N_MODELTYPES; ++i)
......@@ -2457,6 +2459,11 @@ DiagramsModel *UMLDoc::diagramsModel()
return m_diagramsModel;
}
ObjectsModel *UMLDoc::objectsModel()
{
return m_objectsModel;
}
StereotypesModel *UMLDoc::stereotypesModel()
{
return m_stereotypesModel;
......
......@@ -49,6 +49,7 @@ class QPrinter;
class IDChangeLog;
class DiagramsModel;
class ObjectsModel;
class StereotypesModel;
class UMLPackage;
class UMLFolder;
......@@ -237,6 +238,7 @@ public:
DiagramsModel *diagramsModel();
StereotypesModel *stereotypesModel();
ObjectsModel *objectsModel();
private:
void initSaveTimer();
......@@ -314,6 +316,7 @@ private:
bool m_bClosing;
DiagramsModel *m_diagramsModel;
ObjectsModel *m_objectsModel;
StereotypesModel *m_stereotypesModel;
public slots:
......
......@@ -19,6 +19,7 @@
#include "uml.h"
#include "umldoc.h"
#include "umllistview.h"
#include "models/objectsmodel.h"
#include "package.h"
#include "folder.h"
#include "stereotype.h"
......@@ -47,6 +48,7 @@ UMLObject::UMLObject(const UMLObject &other)
: QObject(other.umlParent())
{
other.copyInto(this);
UMLApp::app()->document()->objectsModel()->add(this);
}
/**
......@@ -64,6 +66,7 @@ UMLObject::UMLObject(UMLObject* parent, const QString& name, ID::Type id)
init();
if (id == Uml::ID::None)
m_nId = UniqueID::gen();
UMLApp::app()->document()->objectsModel()->add(this);
}
/**
......@@ -80,6 +83,7 @@ UMLObject::UMLObject(const QString& name, ID::Type id)
init();
if (id == Uml::ID::None)
m_nId = UniqueID::gen();
UMLApp::app()->document()->objectsModel()->add(this);
}
/**
......@@ -92,6 +96,7 @@ UMLObject::UMLObject(UMLObject * parent)
m_name(QString())
{
init();
UMLApp::app()->document()->objectsModel()->add(this);
}
/**
......@@ -106,6 +111,7 @@ UMLObject::~UMLObject()
if (stereotype)
stereotype->decrRefCount();
}
UMLApp::app()->document()->objectsModel()->remove(this);
}
/**
......
Supports Markdown
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