PARP Research Group University of Murcia, Spain


src/qvgui/qvdesigner/slate/slatewindow.h

00001 /*
00002  *      Copyright (C) 2008, 2009. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 #ifndef SLATEWINDOW_H
00022 #define SLATEWINDOW_H
00023 
00024 #include <QMainWindow>
00025 #include <QCloseEvent>
00026 #include <QPair>
00027 #include <QAction>
00028 #include <iostream>
00029 
00030 
00031 class QGraphicsItem;
00032 class QGraphicsScene;
00033 class QGraphicsView;
00034 class Link;
00035 class Node;
00036 class GroupNode;
00037 class ItemNode;
00038 class ItemProperties;
00039 class SlateView;
00040 class QVDesignerGUI;
00041 
00042 #ifndef DOXYGEN_IGNORE_THIS
00043 
00044 
00045 class LinkInfo
00046 {
00047 public:
00049         LinkInfo(): node(0), prop(""), input(false) {  }
00050 
00051         LinkInfo(uint _node, QString _prop, bool _input): node(_node), prop(_prop), input(_input) { }
00052 
00053         bool operator==(const LinkInfo &other) const { return (node == other.getNode() && prop == other.getProp() && input == other.getInput()); }
00054 
00055         uint getNode() const { return node; }
00056 
00057         void setNode(uint _node) { node = _node; }
00058 
00059         QString getProp() const { return prop; }
00060 
00061         void setProp(QString _prop) { prop = _prop; }
00062 
00063         bool getInput() const { return input; }
00064 
00065         void setInput(bool _input) { input = _input; }
00066 
00067 protected:
00068         uint node;
00069         QString prop;
00070         bool input;
00071 };
00072 
00073 class GroupInfo
00074 {
00075 public:
00076         GroupInfo(): id(0), name(""), nodes(), subgroups(), visibleNodeLinks(), visibleSubgroupLinks(), pos(0.0, 0.0) { }
00077 
00078         GroupInfo(uint _id, QString _name): id(_id), name(_name), nodes(), subgroups(), visibleNodeLinks(), visibleSubgroupLinks(), pos(0.0, 0.0) { }
00079 
00080         uint getId() const { return id; }
00081 
00082         QString getName() const { return name; }
00083 
00084         void addNode(uint node) { if (!nodes.contains(node)) nodes.append(node); }
00085 
00086         void addSubgroup(uint subgroup) { if (!subgroups.contains(subgroup)) subgroups.append(subgroup); }
00087 
00088         void addNodeLink(LinkInfo link) { if (!visibleNodeLinks.contains(link)) visibleNodeLinks.append(link); }
00089 
00090         void addSubgroupLink(LinkInfo link) { if (!visibleSubgroupLinks.contains(link)) visibleSubgroupLinks.append(link); }
00091 
00092         void delNode(uint node) {
00093                 int pos = nodes.indexOf(node);
00094                 if (pos > 0) nodes.removeAt(pos);
00095         }
00096 
00097         void delNodeLink(LinkInfo link) {
00098                 int pos = visibleNodeLinks.indexOf(link);
00099                 if (pos > 0) visibleNodeLinks.removeAt(pos);
00100         }
00101 
00102         void delSubgroupLink(LinkInfo link) {
00103                 int pos = visibleSubgroupLinks.indexOf(link);
00104                 if (pos > 0) visibleSubgroupLinks.removeAt(pos);
00105         }
00106 
00107         QList<uint> getNodes() const { return nodes; }
00108 
00109         QList<uint> getSubgroups() const { return subgroups; }
00110 
00111         QList<LinkInfo> getNodeLinks() const { return visibleNodeLinks; }
00112 
00113         QList<LinkInfo> getSubgroupLinks() const { return visibleSubgroupLinks; }
00114 
00115         void setPos(QPointF _pos) { pos = _pos; }
00116 
00117         QPointF getPos() const { return pos; }
00118 
00119         void updateNodeId(uint oldId, uint newId) {
00120                 int pos = nodes.indexOf(oldId);
00121                 if (pos >= 0) {
00122                         nodes.removeAt(pos);
00123                         nodes.append(newId);
00124                 }
00125                 for (QList<LinkInfo>::iterator it = visibleNodeLinks.begin(); it != visibleNodeLinks.end(); it++) { // uso un iterador para poder modificar
00126                         if ((*it).getNode() == oldId)
00127                                 (*it).setNode(newId);
00128                 }
00129         }
00130 
00131         void updateSubgroupId(uint oldId, uint newId) {
00132                 int pos = subgroups.indexOf(oldId);
00133                 if (pos >= 0) {
00134                         subgroups.removeAt(pos);
00135                         subgroups.append(newId);
00136                 }
00137                 for (QList<LinkInfo>::iterator it = visibleSubgroupLinks.begin(); it != visibleSubgroupLinks.end(); it++) { // uso un iterador para poder modificar
00138                         if ((*it).getNode() == oldId)
00139                                 (*it).setNode(newId);
00140                 }
00141         }
00142 
00143 protected:
00144         uint id;
00145         QString name;
00146         QList<uint> nodes;
00147         QList<uint> subgroups;
00148         QList<LinkInfo> visibleNodeLinks;
00149         QList<LinkInfo> visibleSubgroupLinks;
00150         QPointF pos;
00151 };
00152 
00153 
00154 // usar QGraphicsItem::collidesWithItem() para meter automátcamente un item dentro de un grupo (debería estar en node)
00155 class SlateWindow : public QMainWindow
00156 {
00157     Q_OBJECT
00158 
00159 public:
00160     SlateWindow(QVDesignerGUI *desig, QWidget * parent = 0);
00161         bool createLink(Node *fromNode, int fromPoint, Node *toNode, int toPoint);
00162         void addLinkLine(uint fromId, QString fromProp, uint toId, QString toProp, bool sinc, bool sequential);
00163         void delLinkLine(uint fromId, QString fromProp, uint toId, QString toProp);
00164         void addItemNode(QString type, QString name, uint id, ItemProperties *item, uint lastId = 0);
00165         void delItemNode(uint id);
00166         void addProperty(uint id, QString propName, int type, bool in, bool out);
00167         void delProperty(uint id, QString propName);
00168         void closeEvent(QCloseEvent *event);
00169         void includeItemType(QString itemType);
00170         void arrangeItems();
00171         void clearSelection();
00172         bool isSelected(QGraphicsItem *item);
00173         void setName(Node *item, QString name);
00174         void setItemName(uint id, QString name);
00175         QPointF getNodePos(uint id) const;
00176         bool moveNode(uint id, QPointF pos);
00177         QList<GroupInfo> getGroups();
00178         void eraseGroups();
00179         uint createGroup(GroupInfo group); // devuelve el identificador del nuevo grupo creado, 0 si aun no se ha creado alguno de sus elementos (nodo o subgrupo)
00180 
00181 public slots:
00182     void showProperties();
00183         void showProperties(Node *node);
00184         void showMessage(QString message);
00185 
00186 private slots:
00187     void del();
00188         void join();
00189     void bringToFront();
00190     void sendToBack();
00191     void updateActions();
00192         void insertItem(QString type);
00193         void run();
00194         void stop();
00195         bool saveAs();
00196         bool open();
00197         bool exportAs();
00198 
00199 signals:
00201         void closed();
00202 
00203 private:
00204     typedef QPair<Node *, Node *> NodePair;
00205 
00206     QPoint startPos;
00207 
00208     void createMenus();
00209     void createToolBars();
00210     void setZValue(int z);
00211     void setupNode(Node *node);
00212     Node *selectedNode() const;
00213     Link *selectedLink() const;
00214     NodePair selectedNodePair() const;
00215     QList<QGraphicsItem *> selectedNodeGroup() const;
00216         QList<QGraphicsItem *> onlyParents(QList<QGraphicsItem *> items) const;
00217     bool saveFile(const QString &fileName, bool xmlFile);
00218     bool exportFile(const QString &fileName);
00219         int precursors(Node *node);
00220 
00221     QMenu *fileMenu;
00222     QMenu *editMenu;
00223         QMenu *insertMenu;
00224         QMenu *insertUserSubmenu;
00225         QList<QMenu *> insertSubmenus;
00226     QToolBar *editToolBar;
00227     QAction *exitAction;
00228     QAction *addSLinkAction;
00229     QAction *addALinkAction;
00230     QAction *addQLinkAction;
00231         QActionGroup *linkGroup;
00232     QAction *joinAction;
00233     QAction *deleteAction;
00234     QAction *bringToFrontAction;
00235     QAction *sendToBackAction;
00236     QAction *propertiesAction;
00237         QAction *runAction;
00238         QAction *stopAction;
00239         QAction *exportAction;
00240         QAction *saveAsAction;
00241         QAction *openAction;
00242 
00243         QStatusBar *statusbar;
00244 
00245     QGraphicsScene *scene;
00246     SlateView *view;
00247         QVDesignerGUI *designer;
00248 
00249     int minZ;
00250     int maxZ;
00251     int seqNumber;
00252 
00253         QMap<uint, Node *> insertNodes;
00254         QMap<uint, QPointF> insertNodesPos;
00255         QMap<QString, Link *> insertLinks;
00256 
00257         QMap<Node *, GroupInfo> createdGroupInfos;
00258         QMap<uint, GroupNode *> createdGroups;
00259 };
00260 
00261 #endif
00262 #endif



QVision framework. PARP research group, copyright 2007, 2008.