Skip to content

Commit

Permalink
• added Node::hasDriver() for convenience
Browse files Browse the repository at this point in the history
• added SchematicElement::id() for convenience, due to this,
PortGraphicsItem::id() is removed
• one can now only drag a wire in data flow direction i.e. from a data
source (output port) to a data sink (input port)
• added metamodel::enums::ElementType::FUNCTION
• functions of a component are now displayed in the component descriptor
hierarchy
• elements in the component descriptor hierarchy now use the qt
ressource system
• since functions are mostly to long to fit in whole, a tool tip display
it all
• function items in the component hierarchy also got a nice icon
  • Loading branch information
Fredo Erxleben committed Mar 13, 2015
1 parent 7e5c193 commit 31b6759
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 39 deletions.
2 changes: 1 addition & 1 deletion ComponentFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ComponentFactory : public QObject {

/**
* @brief instantiateModulePort is a helper method. It does not do everything needed, but a subset,
* so do not call it on its own.
* so do not call it on its own. Use instantiateInputPort() or instantiateOutputPort() respectively.
* @param document
* @param position
* @param id
Expand Down
2 changes: 2 additions & 0 deletions Enumerations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ metamodel::enums::intToElementType(int i) {
return ElementType::CONFIG_BIT;
case (int)ElementType::PORT :
return ElementType::PORT;
case (int) ElementType::FUNCTION:
return ElementType::FUNCTION;
default :
return ElementType::INVALID;
}
Expand Down
1 change: 1 addition & 0 deletions Enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum class ElementType {
CONFIG_BIT_GROUP,
CONFIG_BIT,
PORT,
FUNCTION,
INVALID
};

Expand Down
4 changes: 3 additions & 1 deletion gui/ComponentTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ using namespace q2d::gui;
using namespace q2d::constants;

ComponentTreeView::ComponentTreeView(QWidget* parent) :
QTreeView(parent) {}
QTreeView(parent) {
this->setWordWrap(true);
}

void
ComponentTreeView::mousePressEvent(QMouseEvent* event) {
Expand Down
16 changes: 2 additions & 14 deletions gui/PortGraphicsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ PortGraphicsItem::PortGraphicsItem(QPointF position,
case model::enums::PortDirection::IN:
this->m_defaultPen = PEN_INPUT_PORT;
this->m_defaultBrush = BRUSH_INPUT_PORT;
this->setAcceptDrops(true); // input ports can receive wire drops
break;
case model::enums::PortDirection::IN_OUT:
this->m_defaultPen = PEN_IN_OUT_PORT;
Expand All @@ -61,6 +62,7 @@ PortGraphicsItem::PortGraphicsItem(QPointF position,
case model::enums::PortDirection::OUT:
this->m_defaultPen = PEN_OUTPUT_PORT;
this->m_defaultBrush = BRUSH_OUTPUT_PORT;
this->setAcceptedMouseButtons(Qt::LeftButton); // output ports can be dragged from
break;
default:
this->m_defaultPen = PEN_UNDEFINED_PORT;
Expand All @@ -74,8 +76,6 @@ PortGraphicsItem::PortGraphicsItem(QPointF position,
this->addActual(newActual);

this->setAcceptHoverEvents(true);
this->setAcceptedMouseButtons(Qt::LeftButton);
this->setAcceptDrops(true);
Q_ASSERT(this->actual()->isVisible());
}

Expand Down Expand Up @@ -135,18 +135,6 @@ PortGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) {
event->accept();
}

/**
* @brief PortGraphicsItem::id is a convenience function
* @return
*/
QString
PortGraphicsItem::id() const {
// TODO asserts
// TODO this is a solution by spiraling in…
Document* container = m_scene->document();
return container->entry(this)->id();
}

/**
* @brief PortGraphicsItem::performDrag initializes and performs a QDrag.
*/
Expand Down
1 change: 0 additions & 1 deletion gui/PortGraphicsItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class PortGraphicsItem : public SchematicElement {
static bool wireDrawingMode();
static void setWireDrawingMode(bool mode, QPointF* origin = nullptr);

QString id() const;
signals:

public slots:
Expand Down
4 changes: 4 additions & 0 deletions gui/SchematicElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ SchematicElement::paint(QPainter* painter,
actual->paint(painter, option, widget);
}
}
QString
SchematicElement::id() const {
return m_relatedEntry->id();
}
9 changes: 7 additions & 2 deletions gui/SchematicElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ class SchematicElement : public QGraphicsObject {
*/
QRectF m_boundingRect;

DocumentEntry* m_relatedEntry;

protected:
static const QJsonObject EMPTY_JSON;

DocumentEntry* m_relatedEntry;
Schematic* m_scene;

void setBoundingRect(QRectF rect) {
Expand All @@ -83,6 +82,12 @@ class SchematicElement : public QGraphicsObject {

Schematic* scene() const;

/**
* @brief id is a convenience shortcut for querying the id of the related document entry
* @return
*/
QString id() const;

// for JSON generation
// you must/may want to override these.
virtual QString specificType() = 0;
Expand Down
1 change: 1 addition & 0 deletions icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<file>ressources/icons/outside_port_out.svg</file>
<file>ressources/icons/outside_port_in.svg</file>
<file>ressources/icons/bit_group.svg</file>
<file>ressources/icons/function.svg</file>
</qresource>
</RCC>
5 changes: 5 additions & 0 deletions metamodel/ComponentDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Category.h"
#include "ConfigurationBitDescriptor.h"
#include "FunctionDescriptor.h"
#include "PortDescriptor.h"

#include <QtDebug>
Expand Down Expand Up @@ -103,6 +104,10 @@ ComponentDescriptor::addConfigBitGroup(ConfigBitGroupDescriptor* configBitGroup)
void
ComponentDescriptor::addFunction(QString function) {
m_functions.append(function);

// also create a function descripor item
FunctionDescriptor* funcDes = new FunctionDescriptor(function, this);
this->appendRow(funcDes);
}

QString
Expand Down
9 changes: 1 addition & 8 deletions metamodel/ConfigurationBitDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ ConfigBitGroupDescriptor::ConfigBitGroupDescriptor(QString groupName, unsigned i
this);
this->appendRow(descriptor);
}

// fetch the icon for the group
QString fileName = Application::instance()->getSetting(KEY_FILE_BIT_GROUP).toString();

if (!fileName.isEmpty()) {
QIcon icon = QIcon(fileName);
this->setIcon(icon);
}
this->setIcon(QIcon(":/icons/ressources/icons/bit_group.svg"));
}

QString
Expand Down
9 changes: 9 additions & 0 deletions metamodel/FunctionDescriptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "FunctionDescriptor.h"

using namespace q2d::metamodel;

FunctionDescriptor::FunctionDescriptor(QString function, ComponentDescriptor* parent)
: ComponentElement(function, parent){
this->setIcon(QIcon(":/icons/ressources/icons/function.svg"));
this->setToolTip(function);
}
23 changes: 23 additions & 0 deletions metamodel/FunctionDescriptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef FUNCTIONDESCRIPTOR_H
#define FUNCTIONDESCRIPTOR_H

#include "ComponentElement.h"

namespace q2d {
namespace metamodel {

class FunctionDescriptor
: public ComponentElement {
private:
public:
explicit FunctionDescriptor(QString function, ComponentDescriptor* parent);

virtual int type() const override {
return enums::elementTypeToInt(enums::ElementType::FUNCTION);
}
};

} // namespace metamodel
} // namespace q2d

#endif // FUNCTIONDESCRIPTOR_H
13 changes: 3 additions & 10 deletions metamodel/PortDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,17 @@ PortDescriptor::PortDescriptor(QString name,
QString setting;
switch (direction) {
case model::enums::PortDirection::IN :
setting = KEY_FILE_PORT_IN;
this->setIcon(QIcon(":/icons/ressources/icons/port_in.svg"));
break;
case model::enums::PortDirection::OUT :
setting = KEY_FILE_PORT_OUT;
this->setIcon(QIcon(":/icons/ressources/icons/port_out.svg"));
break;
case model::enums::PortDirection::IN_OUT :
setting = KEY_FILE_PORT_INOUT;
this->setIcon(QIcon(":/icons/ressources/icons/port_inout.svg"));
break;
default:
setting = QString();
}

QString fileName = Application::instance()->getSetting(setting).toString();

if (!fileName.isEmpty()) {
QIcon icon = QIcon(fileName);
this->setIcon(icon);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions model/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Node : public ModelElement {
return m_drivenElements;
}

bool hasDriver(){
return m_driver != nullptr;
}

virtual QString toString() const override;
};

Expand Down
6 changes: 4 additions & 2 deletions q2d.pro
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ SOURCES +=\
MapModel.cpp \
model/Port.cpp \
gui/Schematic.cpp \
gui/SchematicElement.cpp
gui/SchematicElement.cpp \
metamodel/FunctionDescriptor.cpp

HEADERS +=\
gui/MainWindow.h \
Expand Down Expand Up @@ -124,7 +125,8 @@ HEADERS +=\
MapModel.h \
model/Port.h \
gui/Schematic.h \
gui/SchematicElement.h
gui/SchematicElement.h \
metamodel/FunctionDescriptor.h

INCLUDEPATH +=\
$$picosatDir \
Expand Down
124 changes: 124 additions & 0 deletions ressources/icons/function.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 31b6759

Please sign in to comment.