Commit 593cf96f authored by Alex Diev's avatar Alex Diev
Browse files

Merge branch 'dengof_#83' into 'master'

Combobox for kind of PI attributes

Closes #83

See merge request esa/taste3!111
parents 47568a0f 69b1c55c
Pipeline #1519 failed with stage
......@@ -122,6 +122,7 @@ SOURCES += \
tab_interface/properties/contextparametersmodel.cpp \
tab_interface/properties/delegates/comboboxdelegate.cpp \
tab_interface/properties/delegates/functionattrdelegate.cpp \
tab_interface/properties/delegates/interfaceattrdelegate.cpp \
tab_interface/properties/delegates/propertytypedelegate.cpp \
tab_interface/properties/dynamicproperty.cpp \
tab_interface/properties/dynamicpropertyconfig.cpp \
......@@ -226,6 +227,7 @@ HEADERS += \
tab_interface/properties/contextparametersmodel.h \
tab_interface/properties/delegates/comboboxdelegate.h \
tab_interface/properties/delegates/functionattrdelegate.h \
tab_interface/properties/delegates/interfaceattrdelegate.h \
tab_interface/properties/delegates/propertytypedelegate.h \
tab_interface/properties/dynamicproperty.h \
tab_interface/properties/dynamicpropertyconfig.h \
......
......@@ -21,6 +21,8 @@
#include "aadlobjectfunction.h"
#include "aadlobjectsmodel.h"
#include <QMetaEnum>
namespace taste3 {
namespace aadl {
......@@ -89,61 +91,45 @@ bool AADLObjectIface::isRequired() const
return direction() == IfaceType::Required;
}
QString AADLObjectIface::kind() const
{
return attr(meta::Props::token(meta::Props::Token::kind)).toString();
}
bool AADLObjectIface::setKind(const QString &kind)
QMap<AADLObjectIface::OperationKind, QString> AADLObjectIface::xmlKindNames()
{
if (this->kind() != kind) {
setAttr(meta::Props::token(meta::Props::Token::kind), kind);
return true;
static QMap<AADLObjectIface::OperationKind, QString> result;
if (result.isEmpty()) {
const QMetaEnum &me = QMetaEnum::fromType<taste3::aadl::AADLObjectIface::OperationKind>();
for (int i = 0; i < me.keyCount(); ++i) {
const AADLObjectIface::OperationKind k = static_cast<AADLObjectIface::OperationKind>(me.value(i));
result.insert(k, QString(me.key(i)).toUpper() + QLatin1Literal("_OPERATION"));
}
}
return false;
return result;
}
qint32 AADLObjectIface::period() const
QString AADLObjectIface::kindToString(AADLObjectIface::OperationKind k)
{
return attr(meta::Props::token(meta::Props::Token::period)).toInt();
static const QMap<AADLObjectIface::OperationKind, QString> &kindNamesXml = xmlKindNames();
return kindNamesXml.contains(k) ? kindNamesXml.value(k) : QString();
}
bool AADLObjectIface::setPeriod(qint32 period)
AADLObjectIface::OperationKind AADLObjectIface::kindFromString(const QString &k)
{
if (this->period() != period) {
setAttr(meta::Props::token(meta::Props::Token::period), period);
return true;
}
static const QMap<AADLObjectIface::OperationKind, QString> &kindNamesXml = AADLObjectIface::xmlKindNames();
static const QStringList &names = kindNamesXml.values();
return false;
return names.contains(k) ? kindNamesXml.key(k) : AADLObjectIface::OperationKind::Any;
}
qint32 AADLObjectIface::wcet() const
AADLObjectIface::OperationKind AADLObjectIface::kind() const
{
return attr(meta::Props::token(meta::Props::Token::wcet)).toInt();
return kindFromString(attr(meta::Props::token(meta::Props::Token::kind)).toString());
}
bool AADLObjectIface::setWcet(qint32 wcet)
bool AADLObjectIface::setKind(AADLObjectIface::OperationKind k)
{
if (this->wcet() != wcet) {
setAttr(meta::Props::token(meta::Props::Token::wcet), wcet);
if (this->kind() != k) {
setAttr(meta::Props::token(meta::Props::Token::kind), kindToString(k));
return true;
}
return false;
}
qint32 AADLObjectIface::queueSize() const
{
return attr(meta::Props::token(meta::Props::Token::queue_size)).toInt();
}
bool AADLObjectIface::setQueueSize(qint32 size)
{
if (queueSize() != size) {
setAttr(meta::Props::token(meta::Props::Token::queue_size), size);
return true;
}
return false;
}
......@@ -164,64 +150,6 @@ void AADLObjectIface::addParam(const IfaceParameter &param)
d->m_params.append(param);
}
QString AADLObjectIface::rcmOperationKind() const
{
return prop(meta::Props::token(meta::Props::Token::RCMoperationKind)).toString();
}
bool AADLObjectIface::setRcmOperationKind(const QString &kind)
{
if (rcmOperationKind() != kind) {
setProp(meta::Props::token(meta::Props::Token::RCMoperationKind), kind);
return true;
}
return false;
}
QString AADLObjectIface::deadline() const
{
return prop(meta::Props::token(meta::Props::Token::Deadline)).toString();
}
bool AADLObjectIface::setDeadline(const QString &deadline)
{
if (this->deadline() != deadline) {
setProp(meta::Props::token(meta::Props::Token::Deadline), deadline);
return true;
}
return false;
}
QString AADLObjectIface::rcmPeriod() const
{
return prop(meta::Props::token(meta::Props::Token::RCMperiod)).toString();
}
bool AADLObjectIface::setRcmPeriod(const QString &period)
{
if (rcmPeriod() != period) {
setProp(meta::Props::token(meta::Props::Token::RCMperiod), period);
return true;
}
return false;
}
QString AADLObjectIface::interfaceName() const
{
/// TODO: talk about (props TASTE::) InterfaceName
return attr(meta::Props::token(meta::Props::Token::name)).toString();
}
bool AADLObjectIface::setInterfaceName(const QString &name)
{
/// TODO: talk about (props TASTE::) InterfaceName
if (interfaceName() != name) {
setAttr(meta::Props::token(meta::Props::Token::name), name);
return true;
}
return false;
}
bool AADLObjectIface::labelInheritance() const
{
return prop(meta::Props::token(meta::Props::Token::labelInheritance)).toBool();
......
......@@ -44,9 +44,22 @@ public:
Provided
};
Q_ENUM(IfaceType)
static constexpr IfaceType DefaultDirection { IfaceType::Required };
enum class OperationKind
{
Any = 0,
Cyclic, // period, deadline, wcet
Sporadic, // min interval t,deadline, wcet,queuesize
Protetcted, // deadline, wcet
Unprotected, // deadline, wcet
};
Q_ENUM(OperationKind)
static QMap<AADLObjectIface::OperationKind, QString> xmlKindNames();
static QString kindToString(AADLObjectIface::OperationKind k);
static AADLObjectIface::OperationKind kindFromString(const QString &k);
~AADLObjectIface() override;
AADLObject::AADLObjectType aadlType() const override;
......@@ -56,34 +69,13 @@ public:
bool isProvided() const;
bool isRequired() const;
QString kind() const;
bool setKind(const QString &kind);
qint32 period() const;
bool setPeriod(qint32 period);
qint32 wcet() const;
bool setWcet(qint32 wcet);
qint32 queueSize() const;
bool setQueueSize(qint32 size);
OperationKind kind() const;
bool setKind(OperationKind k);
QVector<IfaceParameter> params() const;
void setParams(const QVector<IfaceParameter> &params);
void addParam(const IfaceParameter &param);
QString rcmOperationKind() const;
bool setRcmOperationKind(const QString &kind);
QString deadline() const;
bool setDeadline(const QString &deadline);
QString rcmPeriod() const;
bool setRcmPeriod(const QString &period);
QString interfaceName() const;
bool setInterfaceName(const QString &name);
bool labelInheritance() const;
bool setLabelInheritance(bool label);
......
......@@ -48,8 +48,8 @@ AADLInterfaceGraphicsItem::AADLInterfaceGraphicsItem(AADLObjectIface *entity, QG
setFlag(QGraphicsItem::ItemIsSelectable);
QPainterPath kindPath;
const QString kind = entity->kind();
if (kind == QStringLiteral("CYCLIC_OPERATION")) {
switch (entity->kind()) {
case AADLObjectIface::OperationKind::Cyclic: {
const qreal kindBaseValue = kHeight;
kindPath.arcTo({ kindPath.currentPosition().x() - kindBaseValue / 2,
kindPath.currentPosition().y() - kindBaseValue, kindBaseValue, kindBaseValue },
......@@ -60,13 +60,17 @@ AADLInterfaceGraphicsItem::AADLInterfaceGraphicsItem(AADLObjectIface *entity, QG
kindPath.currentPosition(),
kindPath.currentPosition() + QPointF(kindBaseValue / 3, -kindBaseValue / 3) });
kindPath.translate(0, kindBaseValue / 2);
} else if (kind == QStringLiteral("SPORADIC_OPERATION")) {
break;
}
case AADLObjectIface::OperationKind::Sporadic: {
const qreal kindBaseValue = kHeight;
kindPath.moveTo(-kindBaseValue / 2, 0);
kindPath.lineTo(0, -kindBaseValue / 4);
kindPath.lineTo(0, kindBaseValue / 4);
kindPath.lineTo(kindBaseValue / 2, 0);
} else if (kind == QStringLiteral("PROTECTED_OPERATION")) {
break;
}
case AADLObjectIface::OperationKind::Protetcted: {
const qreal kindBaseValue = kHeight;
const QRectF rect { -kindBaseValue / 2, -kindBaseValue / 2, kindBaseValue, kindBaseValue * 2 / 3 };
kindPath.addRoundedRect(rect, 2, 2);
......@@ -76,6 +80,9 @@ AADLInterfaceGraphicsItem::AADLInterfaceGraphicsItem(AADLObjectIface *entity, QG
kindPath.arcTo(arcRect, 0, 180);
kindPath.translate(0, rect.height() / 3);
}
default:
break;
}
m_type = new QGraphicsPathItem(kindPath, this);
QPainterPath pp;
......@@ -83,7 +90,7 @@ AADLInterfaceGraphicsItem::AADLInterfaceGraphicsItem(AADLObjectIface *entity, QG
QPointF(2 * kHeight / 3, 0) });
pp.closeSubpath();
m_iface->setPath(pp);
m_text->setPlainText(entity->interfaceName());
m_text->setPlainText(entity->title());
QObject::connect(entity, &AADLObject::attributeChanged, [this, entity](taste3::aadl::meta::Props::Token attr) {
if (attr == taste3::aadl::meta::Props::Token::name) {
......
......@@ -509,11 +509,10 @@ void InterfaceTabDocument::onItemClicked()
<< connection->graphicsPoints() << "\n";
qDebug() << "\nInternal Connection data:"
<< "\n"
<< (connection->entity()->title().isEmpty()
? QStringLiteral("Connection %1<>%2")
.arg(connection->startItem()->entity()->interfaceName(),
connection->endItem()->entity()->interfaceName())
: connection->entity()->title())
<< (connection->entity()->title().isEmpty() ? QStringLiteral("Connection %1<>%2")
.arg(connection->startItem()->entity()->title(),
connection->endItem()->entity()->title())
: connection->entity()->title())
<< "\n"
<< utils::polygon(connection->entity()->coordinates()) << "\n";
} else if (auto function = qobject_cast<aadl::AADLFunctionGraphicsItem *>(sender())) {
......
/*
Copyright (C) 2020 European Space Agency - <maxime.perrotin@esa.int>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>.
*/
#include "interfaceattrdelegate.h"
#include "tab_aadl/aadlcommonprops.h"
#include "tab_aadl/aadlobjectiface.h"
#include "tab_aadl/aadlobjectsmodel.h"
#include "tab_interface/properties/propertieslistmodel.h"
#include <QComboBox>
#include <QDebug>
namespace taste3 {
namespace aadl {
InterfaceAttrDelegate::InterfaceAttrDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
QWidget *InterfaceAttrDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() == PropertiesListModel::ColumnValue)
if (const PropertiesListModel *pModel = qobject_cast<const PropertiesListModel *>(index.model())) {
if (pModel->isAttr(index)) {
const QString &attrName =
pModel->data(pModel->index(PropertiesListModel::ColumnTitle, index.row())).toString();
const meta::Props::Token t = meta::Props::token(attrName);
const AADLObjectIface *iface = qobject_cast<const AADLObjectIface *>(pModel->dataObject());
Q_ASSERT(iface);
switch (t) {
case meta::Props::Token::kind: {
static const QMap<AADLObjectIface::OperationKind, QString> &names = AADLObjectIface::xmlKindNames();
QComboBox *cb = new QComboBox(parent);
QMap<AADLObjectIface::OperationKind, QString>::const_iterator i = names.cbegin();
while (i != names.cend()) {
cb->addItem(i.value(), QVariant::fromValue(i.key()));
++i;
}
return cb;
}
default:
break;
}
}
}
return QStyledItemDelegate::createEditor(parent, option, index);
}
void InterfaceAttrDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (index.column() == PropertiesListModel::ColumnValue)
if (const PropertiesListModel *pModel = qobject_cast<const PropertiesListModel *>(index.model())) {
if (pModel->isAttr(index)) {
const QString &attrName =
pModel->data(pModel->index(PropertiesListModel::ColumnTitle, index.row())).toString();
const meta::Props::Token t = meta::Props::token(attrName);
const AADLObjectIface *iface = qobject_cast<const AADLObjectIface *>(pModel->dataObject());
Q_ASSERT(iface);
switch (t) {
case meta::Props::Token::kind: {
if (QComboBox *cb = qobject_cast<QComboBox *>(editor))
cb->setCurrentIndex(static_cast<int>(iface->kind()));
}
default:
break;
}
}
}
return QStyledItemDelegate::setEditorData(editor, index);
}
} // ns aadl
} // ns taste3
/*
Copyright (C) 2020 European Space Agency - <maxime.perrotin@esa.int>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>.
*/
#pragma once
#include <QStyledItemDelegate>
namespace taste3 {
namespace aadl {
class InterfaceAttrDelegate : public QStyledItemDelegate
{
public:
InterfaceAttrDelegate(QObject *parent = nullptr);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
};
} // ns aadl
} // ns taste3
......@@ -21,6 +21,7 @@
#include "contextparametersmodel.h"
#include "delegates/comboboxdelegate.h"
#include "delegates/functionattrdelegate.h"
#include "delegates/interfaceattrdelegate.h"
#include "delegates/propertytypedelegate.h"
#include "ifaceparametersmodel.h"
#include "propertieslistmodel.h"
......@@ -115,6 +116,12 @@ void PropertiesDialog::initTabs()
new FunctionAttrDelegate(viewAttrs->tableView()));
break;
}
case AADLObject::AADLObjectType::AADLIface: {
viewAttrs->tableView()->setItemDelegateForColumn(PropertiesListModel::ColumnValue,
new InterfaceAttrDelegate(viewAttrs->tableView()));
break;
}
default:
break;
}
......
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