29 #include "applicationview.h"
30 #include <QVBoxLayout>
34 #include <QTreeWidget>
35 #include <QFileDialog>
36 #include <QMessageBox>
37 #include <QInputDialog>
43 #include <arcs/arcsfactory.h>
45 #include "newcomponentdialog.h"
46 #include "editcomponentwidget.h"
47 #include "applicationitems.h"
48 #include "sheetview.h"
51 QDockWidget(
"Application view", parent)
58 setProperty(
"appId", reinterpret_cast<quint64>(application) );
60 connect(
this,SIGNAL(addWidget(QWidget*)),parent,SLOT(addNewTabWidget(QWidget*)));
62 setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
66 setWidget(
new QWidget());
67 QVBoxLayout* vl =
new QVBoxLayout();
68 widget()->setLayout(vl);
69 vl->addWidget(
new QLabel(
"Application mode :"));
72 modeList=
new QComboBox(
this);
79 vl->addWidget(modeList);
80 modeList->setCurrentIndex(0);
82 connect(modeList,SIGNAL(currentIndexChanged(
int)),
this,SLOT(setApplicationMode(
int)));
85 vl->addWidget(treeView);
88 connect(treeView,SIGNAL(itemPressed(QTreeWidgetItem*,
int)),
this,SLOT(handleTreeViewClic(QTreeWidgetItem*,
int)));
89 connect(treeView,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
this,SLOT(handleTreeViewDoubleClic(QTreeWidgetItem*,
int)));
91 selectedCandidate = 0;
95 ApplicationView::~ApplicationView()
98 emit requestAppIdDestroy(property(
"appId"));
122 componentList->takeChildren();
123 processList->takeChildren();
126 for(i=0; i < components.count(); i++)
129 componentList->addChild(cItem);
131 componentList->sortChildren(0,Qt::AscendingOrder);
141 processList->addChild(procItem);
145 for (j=0; j < sheets.count(); j++)
147 procItem->addChild(
new SheetItem(sheets[j]));
151 treeView->expandAll();
152 modeList->setCurrentIndex(modeList->findData(QVariant(application->
getCurrentMode())));
156 void ApplicationView::setApplicationMode(
int mode)
158 application->
setCurrentMode(static_cast<ARCS::ARCSAppFlag>(modeList->itemData(mode).toInt()));
162 void ApplicationView::buildTreeView()
164 treeView =
new QTreeWidget(
this);
165 treeView->setHeaderLabel(
"application");
167 QTreeWidgetItem* appItem =
new QTreeWidgetItem(QStringList(
"application"));
168 appItem->setIcon(0,QIcon(
":icons/document-open-remote.png"));
169 QTreeWidgetItem* ctxItem =
new QTreeWidgetItem(QStringList(
"context"));
170 appItem->addChild(ctxItem);
171 processList =
new QTreeWidgetItem(QStringList(
"processes"));
172 appItem->addChild(processList);
173 processList->setIcon(0,QIcon(
":icons/system-run.png"));
175 componentList =
new QTreeWidgetItem(QStringList(
"components"));
176 componentList->setIcon(0,QIcon(
":icons/code-block.png"));
177 ctxItem->addChild(componentList);
178 QTreeWidgetItem* constantList =
new QTreeWidgetItem(QStringList(
"constants"));
179 ctxItem->addChild(constantList);
180 constantList->setIcon(0,QIcon(
":icons/irc-join-channel.png"));
182 treeView->insertTopLevelItem(0,appItem);
191 QAction* actionDefault =
new QAction(
"Set as active application",
this);
192 connect(actionDefault, SIGNAL(triggered()),
this,SLOT(requestDefaultOwnership()));
193 QAction* action =
new QAction(
"Add library",
this);
194 connect(action,SIGNAL(triggered()),
this,SLOT(addLibrary()));
195 QAction* action2 =
new QAction(
"Add component",
this);
196 connect(action2,SIGNAL(triggered()),
this,SLOT(
addComponent()));
197 removeComponentAction =
new QAction(
"Remove component",
this);
198 connect(removeComponentAction,SIGNAL(triggered()),
this,SLOT(removeComponent()));
199 renameComponentAction =
new QAction(
"Rename component...",
this);
200 connect(renameComponentAction,SIGNAL(triggered()),
this,SLOT(renameComponent()));
201 editComponentAction =
new QAction(
"Edit component",
this);
202 connect(editComponentAction,SIGNAL(triggered()),
this,SLOT(editComponent()));
203 QAction* action3 =
new QAction(
"Add process",
this);
204 connect(action3,SIGNAL(triggered()),
this,SLOT(addProcess()));
205 attachControllerAction =
new QAction(
"Attach controller...",
this);
206 connect(attachControllerAction,SIGNAL(triggered()),
this,SLOT(attachController()));
208 addSheetAction =
new QAction(
"Add sheet",
this);
209 connect(addSheetAction,SIGNAL(triggered()),
this,SLOT(addSheet()));
210 editSheetAction =
new QAction(
"Edit sheet",
this);
211 connect(editSheetAction, SIGNAL(triggered()),
this,SLOT(editSheet()));
212 removeSheetAction =
new QAction(
"Remove sheet",
this);
213 connect(removeSheetAction, SIGNAL(triggered()),
this,SLOT(removeSheet()));
214 renameSheetAction =
new QAction(
"Rename sheet",
this);
215 connect(renameSheetAction, SIGNAL(triggered()),
this,SLOT(
renameSheet()));
217 moveProcessUpAction=
new QAction(
"Move Process up",
this);
218 connect(moveProcessUpAction,SIGNAL(triggered()),
this,SLOT(moveProcessUp()));
219 moveProcessDownAction=
new QAction(
"Move Process down",
this);
220 connect(moveProcessDownAction,SIGNAL(triggered()),
this,SLOT(moveProcessDown()));
222 removeProcessAction=
new QAction(
"Delete Process",
this);
223 connect(removeProcessAction,SIGNAL(triggered()),
this,SLOT(removeProcess()));
225 sheetSeparatorAction =
new QAction(
this);
226 sheetSeparatorAction->setSeparator(
true);
228 processSeparatorAction =
new QAction(
this);
229 processSeparatorAction->setSeparator(
true);
231 componentSeparatorAction =
new QAction(
this);
232 componentSeparatorAction->setSeparator(
true);
235 treeView->addAction(actionDefault);
236 treeView->addAction(action);
237 treeView->addAction(action2);
238 treeView->addAction(processSeparatorAction);
239 treeView->addAction(moveProcessUpAction);
240 treeView->addAction(moveProcessDownAction);
241 treeView->addAction(removeProcessAction);
242 treeView->addAction(componentSeparatorAction);
243 treeView->addAction(renameComponentAction);
244 treeView->addAction(removeComponentAction);
245 treeView->addAction(editComponentAction);
246 treeView->addAction(attachControllerAction);
247 treeView->addAction(action3);
248 treeView->addAction(addSheetAction);
249 treeView->addAction(sheetSeparatorAction);
250 treeView->addAction(editSheetAction);
251 treeView->addAction(renameSheetAction);
252 treeView->addAction(removeSheetAction);
260 treeView->setContextMenuPolicy(Qt::ActionsContextMenu);
264 void ApplicationView::addLibrary()
266 QString res = QFileDialog::getOpenFileName(
this,
"Get a library",QString(),QString(
"*.so"));
290 QTreeWidgetItem* cItem =
new ComponentItem(dlg.getName(),dlg.getType());
291 componentList->addChild(cItem);
292 componentList->sortChildren(0,Qt::AscendingOrder);
297 ctx->createComponent(dlg.getName(),dlg.getType());
302 void ApplicationView::handleTreeViewClic(QTreeWidgetItem *item,
int )
304 selectedCandidate = item;
307 status = (item->type() == ComponentItem::Type) ;
308 componentSeparatorAction->setVisible(status);
309 removeComponentAction->setVisible(status);
310 editComponentAction->setVisible(status);
311 renameComponentAction->setVisible(status);
316 QDrag *drag =
new QDrag(
this);
317 QMimeData *mimeData =
new QMimeData;
320 mimeData->setText(selectedCandidate->text(1));
321 drag->setMimeData(mimeData);
325 status = (item->type() == ProcessItem::Type) ;
326 processSeparatorAction->setVisible(status);
327 attachControllerAction->setVisible(status);
328 addSheetAction->setVisible(status);
329 moveProcessUpAction->setVisible(status);
330 moveProcessDownAction->setVisible(status);
331 removeProcessAction->setVisible(status);
333 status = (item->type() == SheetItem::Type);
334 sheetSeparatorAction->setVisible(status);
335 editSheetAction->setVisible(status);
336 removeSheetAction->setVisible(status);
337 renameSheetAction->setVisible(status);
344 void ApplicationView::handleTreeViewDoubleClic(QTreeWidgetItem* item,
int )
346 selectedCandidate = item;
348 if (item->type() == SheetItem::Type)
351 if (item->type() == ComponentItem::Type)
358 void ApplicationView::removeComponent()
360 if (selectedCandidate)
365 application->removeComponent(ci->getName());
366 emit requestUpdate();
369 delete selectedCandidate;
373 void ApplicationView::renameComponent()
375 if (selectedCandidate)
383 newName = QInputDialog::getText(
this,
"Rename Component",
384 "Please give a new name to the component. \n (Be aware that if you choose a name that already exists, we will ask you again to pick a new name)");
388 if (newName.isEmpty())
393 if (application->
getContext()->renameComponent(ci->getName(),newName))
395 emit requestUpdate();
403 void ApplicationView::editComponent()
405 if (selectedCandidate)
413 ecw->setProperty(
"appId",this->property(
"appId"));
421 void ApplicationView::addProcess()
426 void ApplicationView::removeProcess()
428 if (selectedCandidate)
433 int idx = processList->indexOfChild(selectedCandidate);
435 processList->removeChild(selectedCandidate);
440 void ApplicationView::closeEvent(QCloseEvent *event)
442 QDockWidget::closeEvent(event);
447 void ApplicationView::attachController()
449 if (selectedCandidate)
456 QStringList controllers;
457 for (
int i=0; i < components.count(); i++)
460 if ( aac->
getType() ==
"StateMachine" )
465 if (!controllers.count())
467 QMessageBox::information(
this,
"Controllers not found",
"Controllers not found");
471 QString res = QInputDialog::getItem(
this,
"Attaching a controller",
"Please pick one controller in the list below",controllers,0,
false,&ok);
472 if (ok && !res.isEmpty())
474 pi->setController(res);
477 while ( processList->child(idx) != pi ) { idx++; }
485 void ApplicationView::editSheet()
487 if (selectedCandidate)
498 while ( processList->child(idx) != pi ) { idx++; }
503 sv->setWindowTitle(
"Sheet: " + st.
getName());
504 sv->setProperty(
"appId",this->property(
"appId"));
506 connect(
this,SIGNAL(requestUpdate()),sv,SLOT(updateSheet()));
515 if (selectedCandidate)
522 int idx=processList->indexOfChild(pi);
526 QString newSheetName;
529 newSheetName = QInputDialog::getText(
this,
"Rename Sheet",
530 "Please give a new name to the sheet. \n (Be aware that if you choose a name that already exists, we will ask you again to pick a new name)");
532 while(sheetList.contains(newSheetName));
533 if (newSheetName.isEmpty())
537 emit requestWidgetDestroy(property(
"appId"),
"Sheet: " + si->getName());
540 QString oldSheetName = si->getName();
542 si->setName(newSheetName);
550 QString controllerName = pi->getController();
552 if (controllerName.isEmpty())
555 int controllerShared = 0;
562 if (controllerShared > 1)
564 if ( QMessageBox::question(
this,
"Shared controller",
565 "The sheet you renamed is referenced in the process controller, which is shared.\n" \
566 "Would you like to apply changes in the controller anyway ?",
567 QMessageBox::Yes,QMessageBox::No) == QMessageBox::No)
577 void ApplicationView::removeSheet()
579 if (selectedCandidate)
586 int idx=pi->indexOfChild(si);
590 emit requestWidgetDestroy(property(
"appId"),
"Sheet: " + si->getName());
597 void ApplicationView::moveProcessUp()
599 if(selectedCandidate)
604 int idx=processList->indexOfChild(selectedCandidate);
608 QTreeWidgetItem* item = processList->takeChild(idx);
609 processList->insertChild(idx-1,item);
610 application->swapProcesses(idx,idx-1);
618 void ApplicationView::moveProcessDown()
620 if(selectedCandidate)
625 int idx=processList->indexOfChild(selectedCandidate);
627 if (idx < processList->childCount()-1 )
629 QTreeWidgetItem* item = processList->takeChild(idx);
630 processList->insertChild(idx+1,item);
631 application->swapProcesses(idx,idx+1);
637 void ApplicationView::addSheet()
639 if (selectedCandidate)
647 while ( processList->child(idx) != selectedCandidate ) { idx++; }
654 sheetName = QInputDialog::getText(
this,
"Adding a new sheet",
"Please give a sheet name", QLineEdit::Normal, QString(), &ok );
661 QMessageBox::critical(
this,
"Sheet name error",
"This sheet name already exists for this component",QMessageBox::Ok,0);
665 std::cout <<
"context pointer" << application->
getContext() << std::endl;
QStringList getSheetNames()
For applications running with Qt Widgets.
void renameSheet(QString oldName, QString newName)
This class represents an application.
This class is representing a process under ARCS.
void setCurrentMode(ARCS::ARCSAppFlag flag)
QStringList getComponentList()
void removeSheet(QString s)
void setContext(ARCSContext *ctx)
static ARCSFactory * getInstance()
Returns the instance of the singleton ARCSFactory.
None of the application mode has been selected so far.
bool setController(QString s=QString::null)
void addProcess(ARCSProcess *ap)
void renameSheet(QString oldName, QString newName)
Renames a sheet in the set of transitions.
QVariant getProperty(QString name)
Gets a meta-property from this component.
ARCS::ARCSAppFlag getCurrentMode()
For applications nested in a thread.
Defines a controller component.
Class handling the generic description of a component.
ARCSStateMachine * getStateMachine()
ARCSAbstractComponent * getComponent(QString name)
Retrieves a component by its id.
This class manages components and constants in a given context.
bool loadLibrary(QString path)
Loads a library given the path to it.
ARCSProcess * getProcess(int idx)
ARCSControllerComponent * getController()
ARCSContext * getContext()
void removeProcess(int i)
Removes a process in the list of processes managed by the application.
ARCSSheet & getSheet(QString s)
For applications nested in a thread running with an event loop.
For applications requiring event loops.
Maintains connections between objects.
QString getControllerId()
void addSheet(QString s, ARCSSheet sh)