40 namespace Gecode {
namespace Gist {
44 QGridLayout* layout =
new QGridLayout(
this);
46 QAbstractScrollArea* scrollArea =
new QAbstractScrollArea(
this);
48 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
49 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
50 scrollArea->setAutoFillBackground(
true);
51 QPalette myPalette(scrollArea->palette());
52 myPalette.setColor(QPalette::Window, Qt::white);
53 scrollArea->setPalette(myPalette);
55 canvas->setPalette(myPalette);
56 canvas->setObjectName(
"canvas");
58 connect(scrollArea->horizontalScrollBar(), SIGNAL(valueChanged(
int)),
59 canvas, SLOT(scroll(
void)));
60 connect(scrollArea->verticalScrollBar(), SIGNAL(valueChanged(
int)),
61 canvas, SLOT(scroll(
void)));
63 QVBoxLayout* sa_layout =
new QVBoxLayout();
64 sa_layout->setContentsMargins(0,0,0,0);
65 sa_layout->addWidget(canvas);
66 scrollArea->viewport()->setLayout(sa_layout);
76 QToolButton* autoZoomButton =
new QToolButton();
77 autoZoomButton->setCheckable(
true);
78 autoZoomButton->setIcon(myPic);
82 inspect =
new QAction(
"Inspect",
this);
83 inspect->setShortcut(QKeySequence(
"Return"));
84 connect(
inspect, SIGNAL(triggered()), canvas,
85 SLOT(inspectCurrentNode()));
92 stop =
new QAction(
"Stop search",
this);
93 stop->setShortcut(QKeySequence(
"Esc"));
94 connect(
stop, SIGNAL(triggered()), canvas,
97 reset =
new QAction(
"Reset",
this);
98 reset->setShortcut(QKeySequence(
"Ctrl+R"));
99 connect(
reset, SIGNAL(triggered()), canvas,
102 navUp =
new QAction(
"Up",
this);
103 navUp->setShortcut(QKeySequence(
"Up"));
104 connect(
navUp, SIGNAL(triggered()), canvas,
107 navDown =
new QAction(
"Down",
this);
108 navDown->setShortcut(QKeySequence(
"Down"));
109 connect(
navDown, SIGNAL(triggered()), canvas,
112 navLeft =
new QAction(
"Left",
this);
113 navLeft->setShortcut(QKeySequence(
"Left"));
114 connect(
navLeft, SIGNAL(triggered()), canvas,
117 navRight =
new QAction(
"Right",
this);
118 navRight->setShortcut(QKeySequence(
"Right"));
119 connect(
navRight, SIGNAL(triggered()), canvas,
122 navRoot =
new QAction(
"Root",
this);
123 navRoot->setShortcut(QKeySequence(
"R"));
124 connect(
navRoot, SIGNAL(triggered()), canvas,
127 navNextSol =
new QAction(
"To next solution",
this);
128 navNextSol->setShortcut(QKeySequence(
"Shift+Right"));
129 connect(
navNextSol, SIGNAL(triggered()), canvas,
132 navPrevSol =
new QAction(
"To previous solution",
this);
133 navPrevSol->setShortcut(QKeySequence(
"Shift+Left"));
134 connect(
navPrevSol, SIGNAL(triggered()), canvas,
137 searchNext =
new QAction(
"Next solution",
this);
139 connect(
searchNext, SIGNAL(triggered()), canvas, SLOT(searchOne()));
141 searchAll =
new QAction(
"All solutions",
this);
142 searchAll->setShortcut(QKeySequence(
"A"));
149 hideFailed =
new QAction(
"Hide failed subtrees",
this);
153 unhideAll =
new QAction(
"Unhide all",
this);
154 unhideAll->setShortcut(QKeySequence(
"U"));
162 labelPath =
new QAction(
"Label/clear path",
this);
163 labelPath->setShortcut(QKeySequence(
"Shift+L"));
167 toggleStop =
new QAction(
"Stop/unstop",
this);
171 unstopAll =
new QAction(
"Do not stop in subtree",
this);
172 unstopAll->setShortcut(QKeySequence(
"Shift+X"));
175 zoomToFit =
new QAction(
"Zoom to fit",
this);
176 zoomToFit->setShortcut(QKeySequence(
"Z"));
179 center =
new QAction(
"Center current node",
this);
180 center->setShortcut(QKeySequence(
"C"));
181 connect(
center, SIGNAL(triggered()), canvas, SLOT(centerCurrentNode()));
183 exportPDF =
new QAction(
"Export subtree PDF...",
this);
184 exportPDF->setShortcut(QKeySequence(
"P"));
185 connect(
exportPDF, SIGNAL(triggered()), canvas,
193 print =
new QAction(
"Print...",
this);
194 print->setShortcut(QKeySequence(
"Ctrl+P"));
195 connect(
print, SIGNAL(triggered()), canvas,
198 bookmarkNode =
new QAction(
"Add/remove bookmark",
this);
205 canvas, SLOT(startCompareNodes()));
210 canvas, SLOT(startCompareNodesBeforeFP()));
212 connect(canvas, SIGNAL(addedBookmark(
const QString&)),
213 this, SLOT(addBookmark(
const QString&)));
214 connect(canvas, SIGNAL(removedBookmark(
int)),
215 this, SLOT(removeBookmark(
int)));
217 nullBookmark =
new QAction(
"<none>",
this);
218 nullBookmark->setCheckable(
true);
219 nullBookmark->setChecked(
false);
220 nullBookmark->setEnabled(
false);
225 this, SLOT(selectBookmark(QAction*)));
227 bookmarksMenu =
new QMenu(
"Bookmarks");
228 connect(bookmarksMenu, SIGNAL(aboutToShow()),
229 this, SLOT(populateBookmarksMenu()));
232 setPath =
new QAction(
"Set path",
this);
233 setPath->setShortcut(QKeySequence(
"Shift+P"));
243 this, SLOT(showStats()));
278 nullSolutionInspector =
new QAction(
"<none>",
this);
279 nullSolutionInspector->setCheckable(
true);
280 nullSolutionInspector->setChecked(
false);
281 nullSolutionInspector->setEnabled(
false);
286 this, SLOT(selectSolutionInspector(QAction*)));
288 nullDoubleClickInspector =
new QAction(
"<none>",
this);
289 nullDoubleClickInspector->setCheckable(
true);
290 nullDoubleClickInspector->setChecked(
false);
291 nullDoubleClickInspector->setEnabled(
false);
296 this, SLOT(selectDoubleClickInspector(QAction*)));
298 nullMoveInspector =
new QAction(
"<none>",
this);
299 nullMoveInspector->setCheckable(
true);
300 nullMoveInspector->setChecked(
false);
301 nullMoveInspector->setEnabled(
false);
306 this, SLOT(selectMoveInspector(QAction*)));
308 nullComparator =
new QAction(
"<none>",
this);
309 nullComparator->setCheckable(
true);
310 nullComparator->setChecked(
false);
311 nullComparator->setEnabled(
false);
316 this, SLOT(selectComparator(QAction*)));
318 solutionInspectorMenu =
new QMenu(
"Solution inspectors");
320 doubleClickInspectorMenu =
new QMenu(
"Double click inspectors");
321 doubleClickInspectorMenu->addActions(
323 moveInspectorMenu =
new QMenu(
"Move inspectors");
325 comparatorMenu =
new QMenu(
"Comparators");
330 this, SLOT(inspectWithAction(QAction*)));
333 this, SLOT(inspectBeforeFPWithAction(QAction*)));
335 inspectNodeMenu =
new QMenu(
"Inspect");
336 inspectNodeMenu->addAction(
inspect);
337 connect(inspectNodeMenu, SIGNAL(aboutToShow()),
338 this, SLOT(populateInspectors()));
340 inspectNodeBeforeFPMenu =
new QMenu(
"Inspect before fixpoint");
342 connect(inspectNodeBeforeFPMenu, SIGNAL(aboutToShow()),
343 this, SLOT(populateInspectors()));
344 populateInspectors();
346 contextMenu =
new QMenu(
this);
347 contextMenu->addMenu(inspectNodeMenu);
348 contextMenu->addMenu(inspectNodeBeforeFPMenu);
352 contextMenu->addAction(
center);
354 contextMenu->addSeparator();
359 contextMenu->addSeparator();
370 contextMenu->addSeparator();
372 contextMenu->addMenu(bookmarksMenu);
373 contextMenu->addAction(
setPath);
376 contextMenu->addSeparator();
378 contextMenu->addMenu(doubleClickInspectorMenu);
379 contextMenu->addMenu(solutionInspectorMenu);
380 contextMenu->addMenu(moveInspectorMenu);
382 connect(autoZoomButton, SIGNAL(toggled(
bool)), canvas,
385 connect(canvas, SIGNAL(autoZoomChanged(
bool)),
386 autoZoomButton, SLOT(setChecked(
bool)));
390 while (
opt.inspect.solution(
i)) {
394 while (
opt.inspect.click(
i)) {
398 while (
opt.inspect.move(
i)) {
402 while (
opt.inspect.compare(
i)) {
408 layout->addWidget(scrollArea, 0,0,-1,1);
409 layout->addWidget(canvas->
scaleBar, 1,1, Qt::AlignHCenter);
410 layout->addWidget(autoZoomButton, 0,1, Qt::AlignHCenter);
419 QMetaObject::connectSlotsByName(
this);
423 Gist::resizeEvent(QResizeEvent*) {
428 Gist::addInspector(
Inspector* i0, QAction*& nas, QAction*& nad,
431 actions().indexOf(nullDoubleClickInspector) != -1) {
440 nas =
new QAction(i0->
name().c_str(),
this);
441 nas->setCheckable(
true);
443 solutionInspectorMenu->clear();
446 nad =
new QAction(i0->
name().c_str(),
this);
447 nad->setCheckable(
true);
449 doubleClickInspectorMenu->clear();
450 doubleClickInspectorMenu->addActions(
453 nam =
new QAction(i0->
name().c_str(),
this);
454 nam->setCheckable(
true);
456 moveInspectorMenu->clear();
457 moveInspectorMenu->addActions(
460 QAction* ia =
new QAction(i0->
name().c_str(),
this);
462 QAction* ibfpa =
new QAction(i0->
name().c_str(),
this);
466 ia->setShortcut(QKeySequence(QString(
"Ctrl+")+
468 ibfpa->setShortcut(QKeySequence(QString(
"Ctrl+Alt+")+
479 actions().indexOf(nullDoubleClickInspector) == -1) {
481 for (
int i=0;
i<is.size();
i++) {
483 is[
i]->setChecked(
false);
487 nas->setChecked(
true);
488 selectSolutionInspector(nas);
497 actions().indexOf(nullDoubleClickInspector) == -1) {
499 for (
int i=0;
i<is.size();
i++) {
501 is[
i]->setChecked(
false);
505 nad->setChecked(
true);
506 selectDoubleClickInspector(nad);
515 actions().indexOf(nullDoubleClickInspector) == -1) {
517 for (
int i=0;
i<is.size();
i++) {
519 is[
i]->setChecked(
false);
523 nam->setChecked(
true);
524 selectMoveInspector(nam);
531 for (
int i=0;
i<is.size();
i++) {
533 is[
i]->setChecked(
false);
540 QAction* ncs =
new QAction(
c->name().c_str(),
this);
541 ncs->setCheckable(
true);
543 comparatorMenu->clear();
545 ncs->setChecked(
true);
546 selectComparator(ncs);
549 Gist::~Gist(
void) {
delete canvas; }
552 Gist::on_canvas_contextMenu(QContextMenuEvent* event) {
553 contextMenu->popup(event->globalPos());
557 Gist::on_canvas_statusChanged(VisualNode*
n,
const Statistics& stats,
559 nodeStatInspector->
node(*canvas->
na,
n,stats,finished);
568 stop->setEnabled(
true);
569 reset->setEnabled(
false);
570 navUp->setEnabled(
false);
589 center->setEnabled(
false);
592 print->setEnabled(
false);
599 stop->setEnabled(
false);
600 reset->setEnabled(
true);
602 if ( (
n->isOpen() ||
n->hasOpenChildren()) && (!
n->isHidden()) ) {
609 if (
n->getNumberOfChildren() > 0) {
646 VisualNode*
p =
n->getParent(*canvas->
na);
650 navUp->setEnabled(
false);
654 navUp->setEnabled(
true);
655 unsigned int alt =
n->getAlternative(*canvas->
na);
656 navRight->setEnabled(alt + 1 <
p->getNumberOfChildren());
660 VisualNode* root =
n;
661 while (!root->isRoot())
662 root = root->getParent(*canvas->
na);
663 NextSolCursor nsc(
n,
false, *canvas->
na);
664 PreorderNodeVisitor<NextSolCursor> nsv(nsc);
666 navNextSol->setEnabled(nsv.getCursor().node() != root);
668 NextSolCursor psc(
n,
true, *canvas->
na);
669 PreorderNodeVisitor<NextSolCursor> psv(psc);
671 navPrevSol->setEnabled(psv.getCursor().node() != root);
676 print->setEnabled(
true);
688 Gist::inspectWithAction(QAction*
a) {
693 Gist::inspectBeforeFPWithAction(QAction*
a) {
704 Gist::selectDoubleClickInspector(QAction*
a) {
710 Gist::selectSolutionInspector(QAction*
a) {
716 Gist::selectMoveInspector(QAction*
a) {
722 Gist::selectComparator(QAction*
a) {
727 Gist::selectBookmark(QAction*
a) {
734 Gist::addBookmark(
const QString&
id) {
739 QAction* nb =
new QAction(
id,
this);
740 nb->setCheckable(
true);
745 Gist::removeBookmark(
int idx) {
754 Gist::populateBookmarksMenu(
void) {
755 bookmarksMenu->clear();
757 bookmarksMenu->addSeparator();
762 Gist::populateInspectors(
void) {
763 inspectNodeMenu->clear();
764 inspectNodeMenu->addAction(
inspect);
765 inspectNodeMenu->addSeparator();
767 inspectNodeBeforeFPMenu->clear();
769 inspectNodeBeforeFPMenu->addSeparator();
786 Gist::getSmoothScrollAndZoom(
void) {
790 Gist::setSmoothScrollAndZoom(
bool b) {
794 Gist::getMoveDuringSearch(
void) {
798 Gist::setMoveDuringSearch(
bool b) {
802 Gist::setRecompDistances(
int c_d,
int a_d) {
816 Gist::setShowCopies(
bool b) {
820 Gist::getShowCopies(
void) {
825 Gist::showStats(
void) {