Commit 432bfa24 authored by Ralf Habacker's avatar Ralf Habacker

Add diagram dock widget.

parent bda7ec32
......@@ -438,6 +438,7 @@ set(umbrellobase_SRCS
basictypes.cpp
birdview.cpp
cmdlineexportallviewsevent.cpp
diagramswindow.cpp
docwindow.cpp
dotgenerator.cpp
icon_utils.cpp
......@@ -451,7 +452,6 @@ set(umbrellobase_SRCS
petalnode.cpp
petaltree2uml.cpp
stereotypeswindow.cpp
stereotypesmodel.cpp
toolbarstatearrow.cpp
toolbarstateassociation.cpp
toolbarstate.cpp
......@@ -473,6 +473,11 @@ set(umbrellobase_SRCS
worktoolbar.cpp
)
set(umbrellomodels_SRCS
models/diagramsmodel.cpp
models/stereotypesmodel.cpp
)
kconfig_add_kcfg_files(umbrellobase_SRCS umbrellosettings.kcfgc)
set(libumbrello_SRCS
......@@ -492,6 +497,7 @@ set(libumbrello_SRCS
${libuml_SRCS}
${libumlwidgets_SRCS}
${umbrellobase_SRCS}
${umbrellomodels_SRCS}
)
set(umbrello_SRCS
......
/***************************************************************************
* 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 "diagramswindow.h"
// app includes
#include "models/diagramsmodel.h"
#include "uml.h"
#include "umldoc.h"
#include "umlview.h"
// kde includes
#include <KLocalizedString>
// qt includes
#include <QHeaderView>
#include <QTableView>
#include <QSortFilterProxyModel>
#include <QtDebug>
DiagramsWindow::DiagramsWindow(QWidget *parent)
: QDockWidget(i18n("&Diagrams"), parent)
{
setObjectName(QLatin1String("DiagramsWindow"));
QSortFilterProxyModel *proxy = new QSortFilterProxyModel;
proxy->setSourceModel(UMLApp::app()->document()->diagramsModel());
proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
m_diagramsTree = new QTableView;
m_diagramsTree->setModel(proxy);
m_diagramsTree->setSortingEnabled(true);
m_diagramsTree->verticalHeader()->setDefaultSectionSize(20);
m_diagramsTree->verticalHeader()->setVisible(false);
#if QT_VERSION >= 0x050000
m_diagramsTree->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else
m_diagramsTree->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
#endif
setWidget(m_diagramsTree);
connect(m_diagramsTree, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotDiagramsDoubleClicked(QModelIndex)));
}
DiagramsWindow::~DiagramsWindow()
{
delete m_diagramsTree;
}
void DiagramsWindow::modified()
{
UMLView *v = dynamic_cast<UMLView*>(QObject::sender());
if (!v)
return;
UMLApp::app()->document()->diagramsModel()->emitDataChanged(v);
}
void DiagramsWindow::slotDiagramsDoubleClicked(QModelIndex index)
{
QVariant v = UMLApp::app()->document()->diagramsModel()->data(index, Qt::UserRole);
if (v.canConvert<UMLView*>()) {
UMLView *view = v.value<UMLView*>();
view->showPropertiesDialog(this);
}
}
/***************************************************************************
* 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) 2015 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#ifndef DIAGRAMSWINDOW_H
#define DIAGRAMSWINDOW_H
#include <QDockWidget>
#include <QModelIndex>
class QTableView;
class DiagramsWindow : public QDockWidget
{
Q_OBJECT
public:
explicit DiagramsWindow(QWidget *parent = 0);
~DiagramsWindow();
signals:
public slots:
void modified();
protected slots:
void slotDiagramsDoubleClicked(QModelIndex index);
protected:
QTableView *m_diagramsTree;
};
#endif // DIAGRAMSWINDOW_H
......@@ -123,6 +123,39 @@ QPixmap iconSet(Uml::DiagramType::Enum dt)
}
}
/**
* Return the icon corresponding to the given Diagram_Type.
* @param dt the diagram type
* @return the wanted icon
*/
QPixmap smallIcon(Uml::DiagramType::Enum dt)
{
switch (dt) {
case Uml::DiagramType::UseCase:
return SmallIcon(it_Diagram_Usecase);
case Uml::DiagramType::Collaboration:
return SmallIcon(it_Diagram_Collaboration);
case Uml::DiagramType::Class:
return SmallIcon(it_Diagram_Class);
case Uml::DiagramType::Sequence:
return SmallIcon(it_Diagram_Sequence);
case Uml::DiagramType::State:
return SmallIcon(it_Diagram_State);
case Uml::DiagramType::Activity:
return SmallIcon(it_Diagram_Activity);
case Uml::DiagramType::Component:
return SmallIcon(it_Diagram_Component);
case Uml::DiagramType::Deployment:
return SmallIcon(it_Diagram_Deployment);
case Uml::DiagramType::EntityRelationship:
return SmallIcon(it_Diagram_EntityRelationship);
default:
uDebug() << "Widget_Utils::smallIcon: unknown diagram type "
<< Uml::DiagramType::toString(dt);
return QPixmap();
}
}
/**
* Conversion from icon type to its string name.
* @param type the identification of the icon
......
......@@ -244,6 +244,7 @@ namespace Icon_Utils {
QString toString(IconType type);
QPixmap iconSet(Uml::DiagramType::Enum dt);
QPixmap smallIcon(Uml::DiagramType::Enum dt);
} // namespace
......
/***************************************************************************
* 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 "diagramsmodel.h"
// app includes
#include "umlscene.h"
#include "umlview.h"
#include "uml.h"
#include "umldoc.h"
// kde includes
#include <KLocalizedString>
// qt includes
#include <QtDebug>
DiagramsModel::DiagramsModel()
{
}
int DiagramsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
int count = m_views.size();
return count;
}
int DiagramsModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 3;
}
QVariant DiagramsModel::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("Widgets/Associations"));
else return QVariant();
}
QVariant DiagramsModel::data(const QModelIndex & index, int role) const
{
if (role == Qt::UserRole && index.column() == 0) {
QVariant v;
v.setValue(m_views.at(index.row()).data());
return v;
}
else if (role == Qt::DecorationRole && index.column() == 0) {
UMLView *v = m_views.at(index.row());
return QVariant(Icon_Utils::smallIcon(v->umlScene()->type()));
}
else if (role != Qt::DisplayRole)
return QVariant();
int cCount = columnCount(index);
if (index.column() >= cCount)
return QVariant();
UMLView *v = m_views.at(index.row());
if (index.column() == 0)
return v->umlScene()->name();
else if (index.column() == 1)
return Uml::DiagramType::toStringI18n(v->umlScene()->type());
else
return QVariant(QString::number(v->umlScene()->widgetList().size())
+ QLatin1String("/")
+ QString::number(v->umlScene()->associationList().size()));
}
bool DiagramsModel::addDiagram(UMLView *view)
{
if (m_views.contains(view))
return false;
int index = m_views.size();
beginInsertRows(QModelIndex(), index, index);
m_views.append(view);
endInsertRows();
return true;
}
bool DiagramsModel::removeDiagram(UMLView *view)
{
if (!m_views.contains(view))
return false;
int index = m_views.indexOf(view);
beginRemoveRows(QModelIndex(), index, index);
m_views.removeAll(view);
endRemoveRows();
return true;
}
void DiagramsModel::emitDataChanged(const QModelIndex &index)
{
emit dataChanged(index, index);
}
void DiagramsModel::emitDataChanged(int index)
{
QModelIndex mi = createIndex(index,0);
emit dataChanged(mi, mi);
}
void DiagramsModel::emitDataChanged(UMLView *view)
{
int index = m_views.indexOf(view);
emitDataChanged(index);
}
/***************************************************************************
* 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) 2015 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#ifndef DIAGRAMSMODEL_H
#define DIAGRAMSMODEL_H
// app includes
#include "umlviewlist.h"
// qt includes
#include <QAbstractTableModel>
#include <QPointer>
class UMLView;
Q_DECLARE_METATYPE(UMLView*);
class DiagramsModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit DiagramsModel();
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;
bool addDiagram(UMLView *view);
bool removeDiagram(UMLView *view);
void emitDataChanged(const QModelIndex &index);
void emitDataChanged(int index);
void emitDataChanged(UMLView *view);
protected:
int m_count;
UMLViewList m_views;
};
#endif // STEREOTYPESMODEL_H
......@@ -12,7 +12,7 @@
// app includes
#include "stereotype.h"
#include "stereotypesmodel.h"
#include "models/stereotypesmodel.h"
#include "uml.h"
#include "umldoc.h"
......
......@@ -931,6 +931,7 @@ void UMLApp::initView()
widget->setLayout(m_layout);
setCentralWidget(widget);
m_d->createDiagramsWindow();
m_d->createStereotypesWindow();
// create the tree viewer
......
......@@ -15,6 +15,7 @@
#include "finddialog.h"
#include "findresults.h"
#include "uml.h"
#include "diagramswindow.h"
#include "stereotypeswindow.h"
// kde includes
......@@ -50,7 +51,9 @@ public:
FindDialog findDialog;
FindResults findResults;
QListWidget *logWindow; ///< Logging window.
KToggleAction *viewDiagramsWindow;
KToggleAction *viewStereotypesWindow;
DiagramsWindow *diagramsWindow;
StereotypesWindow *stereotypesWindow;
KTextEditor::Editor *editor;
......@@ -60,7 +63,9 @@ public:
explicit UMLAppPrivate(UMLApp *_parent)
: parent(_parent),
findDialog(_parent),
viewDiagramsWindow(0),
viewStereotypesWindow(0),
diagramsWindow(0),
stereotypesWindow(0),
view(0),
document(0)
......@@ -109,6 +114,17 @@ public slots:
delete document;
}
void createDiagramsWindow()
{
// create the tree viewer
diagramsWindow = new DiagramsWindow(parent);
parent->addDockWidget(Qt::LeftDockWidgetArea, diagramsWindow);
viewDiagramsWindow = parent->actionCollection()->add<KToggleAction>(QLatin1String("view_diagrams_window"));
viewDiagramsWindow->setText(i18n("Diagrams"));
connect(viewDiagramsWindow, SIGNAL(triggered(bool)), diagramsWindow, SLOT(setVisible(bool)));
}
void createStereotypesWindow()
{
// create the tree viewer
......
......@@ -44,7 +44,8 @@
#include "umlscene.h"
#include "version.h"
#include "worktoolbar.h"
#include "stereotypesmodel.h"
#include "models/diagramsmodel.h"
#include "models/stereotypesmodel.h"
// kde includes
#include <kio/job.h>
......@@ -115,6 +116,7 @@ UMLDoc::UMLDoc()
m_bTypesAreResolved(true),
m_pCurrentRoot(0),
m_bClosing(false),
m_diagramsModel(new DiagramsModel),
m_stereotypesModel(new StereotypesModel(&m_stereoList))
{
for (int i = 0; i < Uml::ModelType::N_MODELTYPES; ++i)
......@@ -193,6 +195,7 @@ UMLDoc::~UMLDoc()
delete m_pChangeLog;
qDeleteAll(m_stereoList);
delete m_stereotypesModel;
delete m_diagramsModel;
}
/**
......@@ -214,6 +217,7 @@ void UMLDoc::addView(UMLView *view)
}
DEBUG(DBG_SRC) << view->umlScene()->name() << " to folder " << *f << " (" << f->name() << ")";
f->addView(view);
m_diagramsModel->addDiagram(view);
UMLApp * pApp = UMLApp::app();
if (pApp->listView()) {
......@@ -256,6 +260,7 @@ void UMLDoc::removeView(UMLView *view, bool enforceCurrentView)
uError() << view->umlScene()->name() << ": view->getFolder() returns NULL";
return;
}
m_diagramsModel->removeDiagram(view);
f->removeView(view);
UMLView *currentView = UMLApp::app()->currentView();
if (currentView == view) {
......@@ -2446,6 +2451,11 @@ void UMLDoc::resolveTypes()
qApp->processEvents(); // give UI events a chance
}
DiagramsModel *UMLDoc::diagramsModel()
{
return m_diagramsModel;
}
StereotypesModel *UMLDoc::stereotypesModel()
{
return m_stereotypesModel;
......
......@@ -48,6 +48,7 @@ class QDomElement;
class QPrinter;
class IDChangeLog;
class DiagramsModel;
class StereotypesModel;
class UMLPackage;
class UMLFolder;
......@@ -234,6 +235,7 @@ public:
void resolveTypes();
DiagramsModel *diagramsModel();
StereotypesModel *stereotypesModel();
private:
......@@ -311,6 +313,7 @@ private:
*/
bool m_bClosing;
DiagramsModel *m_diagramsModel;
StereotypesModel *m_stereotypesModel;
public slots:
......
......@@ -21,10 +21,11 @@
//#include "umlview.h"
#include <QList>
#include <QPointer>
class UMLView;
typedef QList<UMLView*> UMLViewList;
typedef QListIterator<UMLView*> UMLViewListIt;
typedef QList<QPointer<UMLView>> UMLViewList;
typedef QListIterator<QPointer<UMLView>> UMLViewListIt;
#endif
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