44 namespace Gecode {
namespace Gist {
48 QGridLayout* layout =
new QGridLayout(
this);
50 QAbstractScrollArea* scrollArea =
new QAbstractScrollArea(
this);
52 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
53 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
54 scrollArea->setAutoFillBackground(
true);
55 QPalette myPalette(scrollArea->palette());
56 myPalette.setColor(QPalette::Window, Qt::white);
57 scrollArea->setPalette(myPalette);
59 canvas->setPalette(myPalette);
60 canvas->setObjectName(
"canvas");
62 connect(scrollArea->horizontalScrollBar(), SIGNAL(valueChanged(
int)),
63 canvas, SLOT(scroll(
void)));
64 connect(scrollArea->verticalScrollBar(), SIGNAL(valueChanged(
int)),
65 canvas, SLOT(scroll(
void)));
67 QVBoxLayout* sa_layout =
new QVBoxLayout();
68 sa_layout->setContentsMargins(0,0,0,0);
69 sa_layout->addWidget(canvas);
70 scrollArea->viewport()->setLayout(sa_layout);
80 QToolButton* autoZoomButton =
new QToolButton();
81 autoZoomButton->setCheckable(
true);
82 autoZoomButton->setIcon(myPic);
86 inspect =
new QAction(
"Inspect",
this);
87 inspect->setShortcut(QKeySequence(
"Return"));
88 connect(
inspect, SIGNAL(triggered()), canvas,
89 SLOT(inspectCurrentNode()));
96 stop =
new QAction(
"Stop search",
this);
97 stop->setShortcut(QKeySequence(
"Esc"));
98 connect(
stop, SIGNAL(triggered()), canvas,
101 reset =
new QAction(
"Reset",
this);
102 reset->setShortcut(QKeySequence(
"Ctrl+R"));
103 connect(
reset, SIGNAL(triggered()), canvas,
106 navUp =
new QAction(
"Up",
this);
107 navUp->setShortcut(QKeySequence(
"Up"));
108 connect(
navUp, SIGNAL(triggered()), canvas,
111 navDown =
new QAction(
"Down",
this);
112 navDown->setShortcut(QKeySequence(
"Down"));
113 connect(
navDown, SIGNAL(triggered()), canvas,
116 navLeft =
new QAction(
"Left",
this);
117 navLeft->setShortcut(QKeySequence(
"Left"));
118 connect(
navLeft, SIGNAL(triggered()), canvas,
121 navRight =
new QAction(
"Right",
this);
122 navRight->setShortcut(QKeySequence(
"Right"));
123 connect(
navRight, SIGNAL(triggered()), canvas,
126 navRoot =
new QAction(
"Root",
this);
127 navRoot->setShortcut(QKeySequence(
"R"));
128 connect(
navRoot, SIGNAL(triggered()), canvas,
131 navNextSol =
new QAction(
"To next solution",
this);
132 navNextSol->setShortcut(QKeySequence(
"Shift+Right"));
133 connect(
navNextSol, SIGNAL(triggered()), canvas,
136 navPrevSol =
new QAction(
"To previous solution",
this);
137 navPrevSol->setShortcut(QKeySequence(
"Shift+Left"));
138 connect(
navPrevSol, SIGNAL(triggered()), canvas,
141 searchNext =
new QAction(
"Next solution",
this);
143 connect(
searchNext, SIGNAL(triggered()), canvas, SLOT(searchOne()));
145 searchAll =
new QAction(
"All solutions",
this);
146 searchAll->setShortcut(QKeySequence(
"A"));
153 hideFailed =
new QAction(
"Hide failed subtrees",
this);
157 unhideAll =
new QAction(
"Unhide all",
this);
158 unhideAll->setShortcut(QKeySequence(
"U"));
166 labelPath =
new QAction(
"Label/clear path",
this);
167 labelPath->setShortcut(QKeySequence(
"Shift+L"));
171 toggleStop =
new QAction(
"Stop/unstop",
this);
175 unstopAll =
new QAction(
"Do not stop in subtree",
this);
176 unstopAll->setShortcut(QKeySequence(
"Shift+X"));
179 zoomToFit =
new QAction(
"Zoom to fit",
this);
180 zoomToFit->setShortcut(QKeySequence(
"Z"));
183 center =
new QAction(
"Center current node",
this);
184 center->setShortcut(QKeySequence(
"C"));
185 connect(
center, SIGNAL(triggered()), canvas, SLOT(centerCurrentNode()));
187 exportPDF =
new QAction(
"Export subtree PDF...",
this);
188 exportPDF->setShortcut(QKeySequence(
"P"));
189 connect(
exportPDF, SIGNAL(triggered()), canvas,
197 print =
new QAction(
"Print...",
this);
198 print->setShortcut(QKeySequence(
"Ctrl+P"));
199 connect(
print, SIGNAL(triggered()), canvas,
202 bookmarkNode =
new QAction(
"Add/remove bookmark",
this);
209 canvas, SLOT(startCompareNodes()));
214 canvas, SLOT(startCompareNodesBeforeFP()));
216 connect(canvas, SIGNAL(addedBookmark(
const QString&)),
217 this, SLOT(addBookmark(
const QString&)));
218 connect(canvas, SIGNAL(removedBookmark(
int)),
219 this, SLOT(removeBookmark(
int)));
221 nullBookmark =
new QAction(
"<none>",
this);
222 nullBookmark->setCheckable(
true);
223 nullBookmark->setChecked(
false);
224 nullBookmark->setEnabled(
false);
229 this, SLOT(selectBookmark(QAction*)));
231 bookmarksMenu =
new QMenu(
"Bookmarks");
232 connect(bookmarksMenu, SIGNAL(aboutToShow()),
233 this, SLOT(populateBookmarksMenu()));
236 setPath =
new QAction(
"Set path",
this);
237 setPath->setShortcut(QKeySequence(
"Shift+P"));
247 this, SLOT(showStats()));
282 nullSolutionInspector =
new QAction(
"<none>",
this);
283 nullSolutionInspector->setCheckable(
true);
284 nullSolutionInspector->setChecked(
false);
285 nullSolutionInspector->setEnabled(
false);
290 this, SLOT(selectSolutionInspector(QAction*)));
292 nullDoubleClickInspector =
new QAction(
"<none>",
this);
293 nullDoubleClickInspector->setCheckable(
true);
294 nullDoubleClickInspector->setChecked(
false);
295 nullDoubleClickInspector->setEnabled(
false);
300 this, SLOT(selectDoubleClickInspector(QAction*)));
302 nullMoveInspector =
new QAction(
"<none>",
this);
303 nullMoveInspector->setCheckable(
true);
304 nullMoveInspector->setChecked(
false);
305 nullMoveInspector->setEnabled(
false);
310 this, SLOT(selectMoveInspector(QAction*)));
312 nullComparator =
new QAction(
"<none>",
this);
313 nullComparator->setCheckable(
true);
314 nullComparator->setChecked(
false);
315 nullComparator->setEnabled(
false);
320 this, SLOT(selectComparator(QAction*)));
322 solutionInspectorMenu =
new QMenu(
"Solution inspectors");
324 doubleClickInspectorMenu =
new QMenu(
"Double click inspectors");
325 doubleClickInspectorMenu->addActions(
327 moveInspectorMenu =
new QMenu(
"Move inspectors");
329 comparatorMenu =
new QMenu(
"Comparators");
334 this, SLOT(inspectWithAction(QAction*)));
337 this, SLOT(inspectBeforeFPWithAction(QAction*)));
339 inspectNodeMenu =
new QMenu(
"Inspect");
340 inspectNodeMenu->addAction(
inspect);
341 connect(inspectNodeMenu, SIGNAL(aboutToShow()),
342 this, SLOT(populateInspectors()));
344 inspectNodeBeforeFPMenu =
new QMenu(
"Inspect before fixpoint");
346 connect(inspectNodeBeforeFPMenu, SIGNAL(aboutToShow()),
347 this, SLOT(populateInspectors()));
348 populateInspectors();
350 contextMenu =
new QMenu(
this);
351 contextMenu->addMenu(inspectNodeMenu);
352 contextMenu->addMenu(inspectNodeBeforeFPMenu);
356 contextMenu->addAction(
center);
358 contextMenu->addSeparator();
363 contextMenu->addSeparator();
374 contextMenu->addSeparator();
376 contextMenu->addMenu(bookmarksMenu);
377 contextMenu->addAction(
setPath);
380 contextMenu->addSeparator();
382 contextMenu->addMenu(doubleClickInspectorMenu);
383 contextMenu->addMenu(solutionInspectorMenu);
384 contextMenu->addMenu(moveInspectorMenu);
386 connect(autoZoomButton, SIGNAL(toggled(
bool)), canvas,
389 connect(canvas, SIGNAL(autoZoomChanged(
bool)),
390 autoZoomButton, SLOT(setChecked(
bool)));
394 while (
opt.inspect.solution(
i)) {
398 while (
opt.inspect.click(
i)) {
402 while (
opt.inspect.move(
i)) {
406 while (
opt.inspect.compare(
i)) {
412 layout->addWidget(scrollArea, 0,0,-1,1);
413 layout->addWidget(canvas->
scaleBar, 1,1, Qt::AlignHCenter);
414 layout->addWidget(autoZoomButton, 0,1, Qt::AlignHCenter);
423 QMetaObject::connectSlotsByName(
this);
427 Gist::resizeEvent(QResizeEvent*) {
432 Gist::addInspector(
Inspector* i0, QAction*& nas, QAction*& nad,
435 actions().indexOf(nullDoubleClickInspector) != -1) {
444 nas =
new QAction(i0->
name().c_str(),
this);
445 nas->setCheckable(
true);
447 solutionInspectorMenu->clear();
450 nad =
new QAction(i0->
name().c_str(),
this);
451 nad->setCheckable(
true);
453 doubleClickInspectorMenu->clear();
454 doubleClickInspectorMenu->addActions(
457 nam =
new QAction(i0->
name().c_str(),
this);
458 nam->setCheckable(
true);
460 moveInspectorMenu->clear();
461 moveInspectorMenu->addActions(
464 QAction* ia =
new QAction(i0->
name().c_str(),
this);
466 QAction* ibfpa =
new QAction(i0->
name().c_str(),
this);
470 ia->setShortcut(QKeySequence(QString(
"Ctrl+")+
472 ibfpa->setShortcut(QKeySequence(QString(
"Ctrl+Alt+")+
483 actions().indexOf(nullDoubleClickInspector) == -1) {
485 for (
int i=0;
i<is.size();
i++) {
487 is[
i]->setChecked(
false);
491 nas->setChecked(
true);
492 selectSolutionInspector(nas);
501 actions().indexOf(nullDoubleClickInspector) == -1) {
503 for (
int i=0;
i<is.size();
i++) {
505 is[
i]->setChecked(
false);
509 nad->setChecked(
true);
510 selectDoubleClickInspector(nad);
519 actions().indexOf(nullDoubleClickInspector) == -1) {
521 for (
int i=0;
i<is.size();
i++) {
523 is[
i]->setChecked(
false);
527 nam->setChecked(
true);
528 selectMoveInspector(nam);
535 for (
int i=0;
i<is.size();
i++) {
537 is[
i]->setChecked(
false);
544 QAction* ncs =
new QAction(
c->name().c_str(),
this);
545 ncs->setCheckable(
true);
547 comparatorMenu->clear();
549 ncs->setChecked(
true);
550 selectComparator(ncs);
553 Gist::~Gist(
void) {
delete canvas; }
556 Gist::on_canvas_contextMenu(QContextMenuEvent* event) {
557 contextMenu->popup(event->globalPos());
561 Gist::on_canvas_statusChanged(VisualNode*
n,
const Statistics& stats,
563 nodeStatInspector->
node(*canvas->
na,
n,stats,finished);
572 stop->setEnabled(
true);
573 reset->setEnabled(
false);
574 navUp->setEnabled(
false);
593 center->setEnabled(
false);
596 print->setEnabled(
false);
603 stop->setEnabled(
false);
604 reset->setEnabled(
true);
606 if ( (
n->isOpen() ||
n->hasOpenChildren()) && (!
n->isHidden()) ) {
613 if (
n->getNumberOfChildren() > 0) {
650 VisualNode*
p =
n->getParent(*canvas->
na);
654 navUp->setEnabled(
false);
658 navUp->setEnabled(
true);
659 unsigned int alt =
n->getAlternative(*canvas->
na);
660 navRight->setEnabled(alt + 1 <
p->getNumberOfChildren());
664 VisualNode* root =
n;
665 while (!root->isRoot())
666 root = root->getParent(*canvas->
na);
667 NextSolCursor nsc(
n,
false, *canvas->
na);
668 PreorderNodeVisitor<NextSolCursor> nsv(nsc);
670 navNextSol->setEnabled(nsv.getCursor().node() != root);
672 NextSolCursor psc(
n,
true, *canvas->
na);
673 PreorderNodeVisitor<NextSolCursor> psv(psc);
675 navPrevSol->setEnabled(psv.getCursor().node() != root);
680 print->setEnabled(
true);
692 Gist::inspectWithAction(QAction*
a) {
697 Gist::inspectBeforeFPWithAction(QAction*
a) {
708 Gist::selectDoubleClickInspector(QAction*
a) {
714 Gist::selectSolutionInspector(QAction*
a) {
720 Gist::selectMoveInspector(QAction*
a) {
726 Gist::selectComparator(QAction*
a) {
731 Gist::selectBookmark(QAction*
a) {
738 Gist::addBookmark(
const QString&
id) {
743 QAction* nb =
new QAction(
id,
this);
744 nb->setCheckable(
true);
749 Gist::removeBookmark(
int idx) {
758 Gist::populateBookmarksMenu(
void) {
759 bookmarksMenu->clear();
761 bookmarksMenu->addSeparator();
766 Gist::populateInspectors(
void) {
767 inspectNodeMenu->clear();
768 inspectNodeMenu->addAction(
inspect);
769 inspectNodeMenu->addSeparator();
771 inspectNodeBeforeFPMenu->clear();
773 inspectNodeBeforeFPMenu->addSeparator();
790 Gist::getSmoothScrollAndZoom(
void) {
794 Gist::setSmoothScrollAndZoom(
bool b) {
798 Gist::getMoveDuringSearch(
void) {
802 Gist::setMoveDuringSearch(
bool b) {
806 Gist::setRecompDistances(
int c_d,
int a_d) {
820 Gist::setShowCopies(
bool b) {
824 Gist::getShowCopies(
void) {
829 Gist::showStats(
void) {