orderconnectionsdialog.cpp
1 /*
2  name: tools/editor/orderconnectionsdialog.cpp
3 
4  This file is part of ARCS - Augmented Reality Component System
5  (version 2-current), written by Jean-Yves Didier
6  for IBISC Laboratory (http://www.ibisc.univ-evry.fr)
7 
8  Copyright (C) 2013 Université d'Evry-Val d'Essonne
9 
10  This program is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Please send bugreports with examples or suggestions to
25  jean-yves.didier__at__ibisc.univ-evry.fr
26 */
27 
28 
29 #include "orderconnectionsdialog.h"
30 #include <QTreeWidget>
31 #include <QTreeWidgetItem>
32 
33 #include <QVBoxLayout>
34 #include <QHBoxLayout>
35 #include <QSpacerItem>
36 #include <QPushButton>
37 
38 #include <iostream>
39 
40 
41 OrderConnectionsDialog::OrderConnectionsDialog(ARCSSheet* s, QWidget *parent) :
42  QDialog(parent),sheet(s)
43 {
44  QHBoxLayout* hl1 = new QHBoxLayout();
45  QHBoxLayout* hl2 = new QHBoxLayout();
46  QVBoxLayout* vl1 = new QVBoxLayout();
47  QVBoxLayout* vl2 = new QVBoxLayout();
48 
49  setLayout(vl2);
50  vl2->addLayout(hl1);
51  vl2->addLayout(hl2);
52 
53  connectionTable = new QTreeWidget(this);
54  connectionTable->setColumnCount(4);
55  QStringList headerNames ;
56  headerNames << "Source" << "Signal" << "Slot" << "Destination" ;
57  connectionTable->setHeaderLabels(headerNames);
58  connectionTable->setRootIsDecorated(false);
59  connectionTable->setSelectionMode(QAbstractItemView::SingleSelection);
60 
61  QStringList sources;
62  QStringList destinations;
63  QStringList sgnls;
64  QStringList slts;
65 
66  sheet->getConnections(sources,sgnls,destinations,slts);
67  //connectionTable->setRowCount(sources.count());
68  int i;
69  for (i=0; i< sources.count(); i++)
70  {
71  QStringList rowConnection;
72  rowConnection << sources[i] << sgnls[i] << destinations[i] << slts[i];
73  connectionTable->addTopLevelItem(new QTreeWidgetItem(rowConnection));
74  }
75  for (i=0; i< 4; i++)
76  connectionTable->resizeColumnToContents(i);
77 
78  hl1->addWidget(connectionTable);
79  hl1->addLayout(vl1);
80 
81  vl1->addStretch();
82  QPushButton* upButton = new QPushButton("Move up", this);
83  QPushButton* downButton = new QPushButton("Move down", this);
84 
85  vl1->addWidget(upButton);
86  vl1->addWidget(downButton);
87  vl1->addStretch();
88 
89  QPushButton* okButton = new QPushButton("Ok", this);
90  QPushButton* cancelButton = new QPushButton("Cancel",this);
91 
92  hl2->addStretch();
93  hl2->addWidget(okButton);
94  hl2->addWidget(cancelButton);
95 
96  connect(upButton,SIGNAL(clicked()),this,SLOT(moveUp()));
97  connect(downButton,SIGNAL(clicked()),this,SLOT(moveDown()));
98  connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
99  connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
100 }
101 
102 void OrderConnectionsDialog::moveUp()
103 {
104  int pos = connectionTable->indexOfTopLevelItem(connectionTable->currentItem());
105  if (pos > 0)
106  {
107  permutations.append(QPair<int,int>(pos,pos-1));
108  QTreeWidgetItem* qtwi = connectionTable->takeTopLevelItem(pos);
109  connectionTable->insertTopLevelItem(pos-1,qtwi);
110  connectionTable->setCurrentItem(qtwi);
111  }
112 }
113 
114 void OrderConnectionsDialog::moveDown()
115 {
116  int pos = connectionTable->indexOfTopLevelItem(connectionTable->currentItem());
117  if (pos < connectionTable->topLevelItemCount() - 1)
118  {
119  permutations.append(QPair<int,int>(pos,pos+1));
120  QTreeWidgetItem* qtwi = connectionTable->takeTopLevelItem(pos);
121  connectionTable->insertTopLevelItem(pos+1,qtwi);
122  connectionTable->setCurrentItem(qtwi);
123  }
124 }
125 
126 void OrderConnectionsDialog::accept()
127 {
128  for (int i=0; i< permutations.count(); i++)
129  sheet->swapConnections(permutations[i].first,permutations[i].second);
130  QDialog::accept();
131 }
Maintains connections between objects.
Definition: arcssheet.h:48