Commit cba7534e authored by Ralf Habacker's avatar Ralf Habacker

Add dock window for stereotypes using a QTableView.

We need this for inspecting stereotypes.

CCBUG:345546
parent 3b16b05c
......@@ -435,6 +435,8 @@ set(umbrellobase_SRCS
port.cpp
stereotype.cpp
template.cpp
stereotypeswindow.cpp
stereotypesmodel.cpp
toolbarstatearrow.cpp
toolbarstateassociation.cpp
toolbarstate.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) 2015 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#include "stereotypesmodel.h"
// app includes
#include "stereotype.h"
#include "uml.h"
#include "umldoc.h"
// kde includes
#include <KLocalizedString>
// qt includes
#include <QtDebug>
// TODO: remove in 2.18
#define I18N(a) QLatin1String(a)
StereotypesModel::StereotypesModel(UMLStereotypeList *stereotypes)
: m_count(0),
m_stereotypes(stereotypes)
{
}
int StereotypesModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
int count = m_stereotypes->count();
return count;
}
int StereotypesModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 2;
}
QVariant StereotypesModel::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("Usage"));
else return QVariant();
}
QVariant StereotypesModel::data(const QModelIndex & index, int role) const
{
if (role == Qt::UserRole && index.column() == 0) {
QVariant v;
v.setValue(m_stereotypes->at(index.row()));
return v;
}
if (role != Qt::DisplayRole)
return QVariant();
int cCount = columnCount(index);
if (index.column() >= cCount)
return QVariant();
UMLStereotype *s = m_stereotypes->at(index.row());
if (cCount == 1) {
QString a = s->name() + QString(QLatin1String(" (%1)")).arg(s->refCount());
return a;
}
// table view
if (index.column() == 0)
return s->name();
else
return s->refCount();
}
bool StereotypesModel::addStereotype(UMLStereotype *stereotype)
{
if (m_stereotypes->contains(stereotype))
return false;
int index = m_stereotypes->count();
beginInsertRows(QModelIndex(), index, index);
m_stereotypes->append(stereotype);
endInsertRows();
return true;
}
bool StereotypesModel::removeStereotype(UMLStereotype *stereotype)
{
if (!m_stereotypes->contains(stereotype))
return false;
int index = m_stereotypes->indexOf(stereotype);
beginRemoveRows(QModelIndex(), index, index);
m_stereotypes->removeAll(stereotype);
endRemoveRows();
return true;
}
void StereotypesModel::emitDataChanged(const QModelIndex &index)
{
emit dataChanged(index, index);
}
void StereotypesModel::emitDataChanged(int index)
{
QModelIndex mi = createIndex(index,0);
emit dataChanged(mi, mi);
}
/***************************************************************************
* 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 STEREOTYPESMODEL_H
#define STEREOTYPESMODEL_H
// app includes
#include "umlstereotypelist.h"
// qt includes
#include <QAbstractTableModel>
class UMLStereotype;
Q_DECLARE_METATYPE(UMLStereotype*);
class StereotypesModel : public QAbstractTableModel
{
Q_OBJECT
public:
StereotypesModel(UMLStereotypeList *stereotypes);
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 addStereotype(UMLStereotype *stereotype);
bool removeStereotype(UMLStereotype *stereotype);
void emitDataChanged(const QModelIndex &index);
void emitDataChanged(int index);
protected:
int m_count;
UMLStereotypeList *m_stereotypes;
};
#endif // STEREOTYPESMODEL_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) 2015 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#include "stereotypeswindow.h"
// app includes
#include "stereotype.h"
#include "stereotypesmodel.h"
#include "uml.h"
#include "umldoc.h"
// kde includes
#include <KLocalizedString>
// qt includes
#include <QHeaderView>
#include <QTableView>
#include <QSortFilterProxyModel>
#include <QtDebug>
// TODO: remove in 2.18
#define I18N(a) QLatin1String(a)
StereotypesWindow::StereotypesWindow(QWidget *parent)
: QDockWidget(I18N("&Stereotypes"), parent)
{
setObjectName(QLatin1String("StereotypesWindow"));
QSortFilterProxyModel *proxy = new QSortFilterProxyModel;
proxy->setSourceModel(UMLApp::app()->document()->stereotypesModel());
proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
m_stereotypesTree = new QTableView;
m_stereotypesTree->setModel(proxy);
m_stereotypesTree->setSortingEnabled(true);
m_stereotypesTree->verticalHeader()->setDefaultSectionSize(20);
m_stereotypesTree->verticalHeader()->setVisible(false);
#if QT_VERSION >= 0x050000
m_stereotypesTree->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else
m_stereotypesTree->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
#endif
setWidget(m_stereotypesTree);
connect(m_stereotypesTree, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotStereotypesDoubleClicked(QModelIndex)));
}
StereotypesWindow::~StereotypesWindow()
{
delete m_stereotypesTree;
}
void StereotypesWindow::modified()
{
UMLStereotype *o = static_cast<UMLStereotype*>(QObject::sender());
if (!o)
return;
int index = UMLApp::app()->document()->stereotypes().indexOf(o);
UMLApp::app()->document()->stereotypesModel()->emitDataChanged(index);
}
void StereotypesWindow::slotStereotypesDoubleClicked(QModelIndex index)
{
QVariant v = UMLApp::app()->document()->stereotypesModel()->data(index, Qt::UserRole);
if (v.canConvert<UMLStereotype*>()) {
UMLStereotype *s = v.value<UMLStereotype*>();
s->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 STEREOTYPESWINDOW_H
#define STEREOTYPESWINDOW_H
#include <QDockWidget>
#include <QModelIndex>
class QTableView;
class StereotypesWindow : public QDockWidget
{
Q_OBJECT
public:
explicit StereotypesWindow(QWidget *parent = 0);
~StereotypesWindow();
signals:
public slots:
void modified();
protected slots:
void slotStereotypesDoubleClicked(QModelIndex index);
protected:
QTableView *m_stereotypesTree;
};
#endif // STEREOTYPESWINDOW_H
......@@ -85,6 +85,7 @@
<Action name="view_show_doc"/>
<Action name="view_show_undo"/>
<Action name="view_show_bird"/>
<Action name="view_show_stereotypes"/>
</Menu>
</MenuBar>
<ToolBar name="mainToolBar" fullWidth="true" newline="true">
......
......@@ -918,6 +918,8 @@ void UMLApp::initView()
widget->setLayout(m_layout);
setCentralWidget(widget);
m_d->createStereotypesWindow();
// create the tree viewer
m_listDock = new QDockWidget(i18n("&Tree View"), this);
m_listDock->setObjectName(QLatin1String("TreeViewDock"));
......
......@@ -15,8 +15,11 @@
#include "finddialog.h"
#include "findresults.h"
#include "uml.h"
#include "stereotypeswindow.h"
// kde includes
#include <KActionCollection>
#include <KToggleAction>
#include <ktexteditor/configinterface.h>
#include <ktexteditor/document.h>
#include <ktexteditor/editor.h>
......@@ -43,16 +46,18 @@ class UMLAppPrivate : public QObject
{
Q_OBJECT
public:
QWidget *parent;
UMLApp *parent;
FindDialog findDialog;
FindResults findResults;
QListWidget *logWindow; ///< Logging window.
KToggleAction *viewStereotypesWindow;
StereotypesWindow *stereotypesWindow;
KTextEditor::Editor *editor;
KTextEditor::View *view;
KTextEditor::Document *document;
explicit UMLAppPrivate(QWidget *_parent)
explicit UMLAppPrivate(UMLApp *_parent)
: parent(_parent),
findDialog(_parent),
view(0),
......@@ -101,6 +106,18 @@ public slots:
delete dialog;
delete document;
}
void createStereotypesWindow()
{
// create the tree viewer
stereotypesWindow = new StereotypesWindow(parent);
parent->addDockWidget(Qt::LeftDockWidgetArea, stereotypesWindow);
viewStereotypesWindow = parent->actionCollection()->add<KToggleAction>(QLatin1String("view_stereotypes_window"));
viewStereotypesWindow->setText(i18n("Stereotypes"));
connect(viewStereotypesWindow, SIGNAL(triggered(bool)), stereotypesWindow, SLOT(setVisible(bool)));
}
};
#endif
......@@ -44,6 +44,7 @@
#include "umlscene.h"
#include "version.h"
#include "worktoolbar.h"
#include "stereotypesmodel.h"
// kde includes
#include <kio/job.h>
......@@ -113,7 +114,8 @@ UMLDoc::UMLDoc()
m_nViewID(Uml::ID::None),
m_bTypesAreResolved(true),
m_pCurrentRoot(0),
m_bClosing(false)
m_bClosing(false),
m_stereotypesModel(new StereotypesModel(&m_stereoList))
{
for (int i = 0; i < Uml::ModelType::N_MODELTYPES; ++i)
m_root[i] = 0;
......@@ -183,6 +185,7 @@ UMLDoc::~UMLDoc()
delete m_pAutoSaveTimer;
m_root[Uml::ModelType::Logical]->removeObject(m_datatypeRoot);
delete m_stereotypesModel;
delete m_datatypeRoot;
for (int i = 0; i < Uml::ModelType::N_MODELTYPES; ++i) {
......@@ -409,8 +412,10 @@ void UMLDoc::closeDocument()
// Remove any stereotypes.
if (stereotypes().count() > 0) {
foreach(UMLStereotype *s, stereotypes())
foreach(UMLStereotype *s, stereotypes()) {
m_stereotypesModel->removeStereotype(s);
delete s;
}
m_stereoList.clear();
}
}
......@@ -1267,9 +1272,8 @@ UMLStereotype * UMLDoc::findStereotypeById(Uml::ID::Type id)
*/
void UMLDoc::addStereotype(UMLStereotype *s)
{
if (! m_stereoList.contains(s)) {
m_stereoList.append(s);
}
if (m_stereotypesModel->addStereotype(s))
emit sigObjectCreated(s);
}
/**
......@@ -1278,9 +1282,8 @@ void UMLDoc::addStereotype(UMLStereotype *s)
*/
void UMLDoc::removeStereotype(UMLStereotype *s)
{
if (m_stereoList.contains(s)) {
m_stereoList.removeAll(s);
}
if (m_stereotypesModel->removeStereotype(s))
emit sigObjectRemoved(s);
}
/**
......@@ -2443,6 +2446,11 @@ void UMLDoc::resolveTypes()
qApp->processEvents(); // give UI events a chance
}
StereotypesModel *UMLDoc::stereotypesModel()
{
return m_stereotypesModel;
}
/**
* Ensures the XMI file is a valid UML file.
* Currently only checks for metamodel=UML.
......
......@@ -48,6 +48,7 @@ class QDomElement;
class QPrinter;
class IDChangeLog;
class StereotypesModel;
class UMLPackage;
class UMLFolder;
class DiagramPrintPage;
......@@ -233,6 +234,8 @@ public:
void resolveTypes();
StereotypesModel *stereotypesModel();
private:
void initSaveTimer();
void createDatatypeFolder();
......@@ -308,6 +311,8 @@ private:
*/
bool m_bClosing;
StereotypesModel *m_stereotypesModel;
public slots:
void slotRemoveUMLObject(UMLObject*o);
void slotAutoSave();
......
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