mirror of
git://projects.qi-hardware.com/nn-usb-fpga.git
synced 2025-04-21 12:27:27 +03:00
Adding bases to the code generator. Code text edit, fixing input/output ID control, etc.
This commit is contained in:
@@ -43,9 +43,11 @@
|
||||
#include <QHash>
|
||||
#include "diagramscene.h"
|
||||
|
||||
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
||||
DiagramScene::DiagramScene(QMenu *itemMenu, MainWindow *ownerWindow,
|
||||
QObject *parent)
|
||||
: QGraphicsScene(parent)
|
||||
{
|
||||
myOwnerWindow = ownerWindow;
|
||||
myItemMenu = itemMenu;
|
||||
myMode = MoveItem;
|
||||
|
||||
@@ -59,8 +61,8 @@ DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
|
||||
myPolygonPath=0;
|
||||
myCorners=0;
|
||||
|
||||
TitleText = new DiagramTextItem(0,0,1,0xFFF,255,"BLOCK NAME HERE (not visible)",
|
||||
QPointF(250,250));
|
||||
TitleText = new DiagramTextItem(0,0,1,0xFFF,255,"BLOCK NAME HERE not visible",
|
||||
QPointF(500,370));
|
||||
addItem(TitleText);
|
||||
|
||||
}
|
||||
@@ -124,14 +126,105 @@ void DiagramScene::doSnapToGrid(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
}
|
||||
}
|
||||
|
||||
QString DiagramScene::createPrototype()
|
||||
{
|
||||
bool first = 1;
|
||||
QString functionPrototype = "\nvoid " +
|
||||
TitleText->toPlainText().replace(' ','_') + "(";
|
||||
|
||||
foreach (QGraphicsItem *item, this->items()) {
|
||||
if (item->type() == DiagramTextItem::Type) {
|
||||
int styleIO = qgraphicsitem_cast<DiagramTextItem*>(item)->styleIO();
|
||||
if(styleIO<256)
|
||||
{
|
||||
int ioID = qgraphicsitem_cast<DiagramTextItem*>(item)->textID();
|
||||
if(!first) functionPrototype += ","; first = 0;
|
||||
switch(styleIO&127)
|
||||
{
|
||||
case 1:
|
||||
functionPrototype += "bool ";
|
||||
break;
|
||||
case 2:
|
||||
functionPrototype += "char ";
|
||||
break;
|
||||
case 3:
|
||||
functionPrototype += "integer ";
|
||||
break;
|
||||
case 4:
|
||||
functionPrototype += "double ";
|
||||
break;
|
||||
case 5:
|
||||
functionPrototype += "float ";
|
||||
break;
|
||||
case 6:
|
||||
functionPrototype += "short ";
|
||||
break;
|
||||
case 7:
|
||||
functionPrototype += "long ";
|
||||
break;
|
||||
case 8:
|
||||
functionPrototype += "unsigned char ";
|
||||
break;
|
||||
case 9:
|
||||
functionPrototype += "unsigned integer ";
|
||||
break;
|
||||
case 10:
|
||||
functionPrototype += "unsigned short ";
|
||||
break;
|
||||
case 11:
|
||||
functionPrototype += "unsigned long ";
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
functionPrototype += (styleIO>>7)? "in":"&out";
|
||||
functionPrototype += "_" + QString::number(ioID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
functionPrototype += ") {";
|
||||
return functionPrototype;
|
||||
}
|
||||
|
||||
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
doSnapToGrid(mouseEvent);
|
||||
QString Text;
|
||||
foreach (QGraphicsItem *item, this->items(mouseEvent->scenePos())) {
|
||||
if (item->type() == DiagramTextItem::Type) {
|
||||
if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()<256)
|
||||
{
|
||||
myOwnerWindow->statusBar->showMessage(
|
||||
qgraphicsitem_cast<DiagramTextItem *>(item)->toPlainText() +
|
||||
tr("\t : Input/Output text label -> {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}"));
|
||||
}
|
||||
else if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()==256)
|
||||
{
|
||||
myOwnerWindow->statusBar->showMessage(
|
||||
qgraphicsitem_cast<DiagramTextItem *>(item)->toPlainText() +
|
||||
tr("\t : Text label -> {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}"));
|
||||
}
|
||||
else if(qgraphicsitem_cast<DiagramTextItem *>(item)->styleIO()==257)
|
||||
{
|
||||
myOwnerWindow->statusBar->showMessage(
|
||||
qgraphicsitem_cast<DiagramTextItem *>(item)->toPlainText() +
|
||||
tr("\t : Editable text label -> {ID = ") +
|
||||
QString::number(qgraphicsitem_cast<DiagramTextItem *>
|
||||
(item)->textID()) + tr("}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
myOwnerWindow->updateProt();
|
||||
|
||||
QString Text;
|
||||
if (mouseEvent->button() != Qt::LeftButton)
|
||||
return;
|
||||
|
||||
int addResult=0;
|
||||
|
||||
switch (myMode)
|
||||
{
|
||||
case InsertText:
|
||||
@@ -146,17 +239,19 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
|
||||
textItem = new DiagramTextItem(0,0,1,myTextType,0,Text,
|
||||
mouseEvent->scenePos());
|
||||
if(addTextItem(textItem))
|
||||
addResult=addTextItem(textItem);
|
||||
if(addResult!=-1)
|
||||
{
|
||||
textItem->setZValue(1000.0);
|
||||
connect(textItem, SIGNAL(lostFocus(DiagramTextItem*)),
|
||||
this, SLOT(editorLostFocus(DiagramTextItem*)));
|
||||
addItem(textItem);
|
||||
textItem->setTextID(addResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete(textItem);
|
||||
QMessageBox::warning(0,"Full","The block can only have only"
|
||||
QMessageBox::warning(0,"Full","The block can only have "
|
||||
"255 text items");
|
||||
}
|
||||
emit textInserted(textItem);
|
||||
@@ -237,7 +332,7 @@ void DiagramScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||
{
|
||||
doSnapToGrid(mouseEvent);
|
||||
if (myMode != EditPolygon && line == 0)
|
||||
if(myMode != EditPolygon && line == 0)
|
||||
QGraphicsScene::mouseReleaseEvent(mouseEvent);
|
||||
}
|
||||
|
||||
@@ -377,7 +472,7 @@ int DiagramScene::fromXmlFormat(QDomDocument document)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
myOwnerWindow->updateProt();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -418,10 +513,10 @@ int DiagramScene::addTextItem(DiagramTextItem * textItem)
|
||||
if(iter==textItemsByID.end())
|
||||
{
|
||||
textItemsByID.insert(i,textItem);
|
||||
return 1;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void DiagramScene::removeTextItem(DiagramTextItem * textItem)
|
||||
|
||||
Reference in New Issue
Block a user