DiagramDesigner/diagramCavas/include/graphicsDataModel/baseModel.h

51 lines
1.2 KiB
C++

#pragma once
#include <QMap>
#include <QSet>
#include <QVector>
#include <QtCore/QJsonObject>
#include <QtCore/QObject>
#include <QtCore/QVariant>
#include <QUuid>
#include "global.h"
/**
* The central class in the Model-View approach. It delivers all kinds
* of information from the backing user data structures that represent
* the graph. The class allows to modify the graph structure: create
* and remove nodes and connections.
*
* We use two types of the unique ids for graph manipulations:
* - NodeId
* - ConnectionId
*/
class BaseModel : public QObject
{
Q_OBJECT
/// @brief Returns node-related data for requested NodeRole.
/**
* @returns Node Caption, Node Caption Visibility, Node Position etc.
*/
virtual QVariant nodeData(QUuid nodeId, NodeRole role) const = 0;
/**
* A utility function that unwraps the `QVariant` value returned from the
* standard `QVariant AbstractGraphModel::nodeData(NodeId, NodeRole)` function.
*/
template<typename T>
T nodeData(QUuid nodeId, NodeRole role) const
{
return nodeData(nodeId, role).value<T>();
}
virtual NodeFlags nodeFlags(NodeId nodeId) const
{
Q_UNUSED(nodeId);
return NodeFlag::NoFlags;
}
};