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);
58 canvas =
new TreeCanvas(root, bab, scrollArea->viewport(),
opt);
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"));
161 toggleStop =
new QAction(
"Stop/unstop",
this);
165 unstopAll =
new QAction(
"Do not stop in subtree",
this);
166 unstopAll->setShortcut(QKeySequence(
"Shift+X"));
169 zoomToFit =
new QAction(
"Zoom to fit",
this);
170 zoomToFit->setShortcut(QKeySequence(
"Z"));
173 center =
new QAction(
"Center current node",
this);
174 center->setShortcut(QKeySequence(
"C"));
175 connect(
center, SIGNAL(triggered()), canvas, SLOT(centerCurrentNode()));
177 exportPDF =
new QAction(
"Export subtree PDF...",
this);
178 exportPDF->setShortcut(QKeySequence(
"P"));
179 connect(
exportPDF, SIGNAL(triggered()), canvas,
187 print =
new QAction(
"Print...",
this);
188 print->setShortcut(QKeySequence(
"Ctrl+P"));
189 connect(
print, SIGNAL(triggered()), canvas,
192 bookmarkNode =
new QAction(
"Add/remove bookmark",
this);
199 canvas, SLOT(startCompareNodes()));
204 canvas, SLOT(startCompareNodesBeforeFP()));
206 connect(canvas, SIGNAL(addedBookmark(
const QString&)),
207 this, SLOT(addBookmark(
const QString&)));
208 connect(canvas, SIGNAL(removedBookmark(
int)),
209 this, SLOT(removeBookmark(
int)));
211 nullBookmark =
new QAction(
"<none>",
this);
212 nullBookmark->setCheckable(
true);
213 nullBookmark->setChecked(
false);
214 nullBookmark->setEnabled(
false);
219 this, SLOT(selectBookmark(QAction*)));
221 bookmarksMenu =
new QMenu(
"Bookmarks");
222 connect(bookmarksMenu, SIGNAL(aboutToShow()),
223 this, SLOT(populateBookmarksMenu()));
226 setPath =
new QAction(
"Set path",
this);
227 setPath->setShortcut(QKeySequence(
"Shift+P"));
237 this, SLOT(showStats()));
270 nullSolutionInspector =
new QAction(
"<none>",
this);
271 nullSolutionInspector->setCheckable(
true);
272 nullSolutionInspector->setChecked(
false);
273 nullSolutionInspector->setEnabled(
false);
278 this, SLOT(selectSolutionInspector(QAction*)));
280 nullDoubleClickInspector =
new QAction(
"<none>",
this);
281 nullDoubleClickInspector->setCheckable(
true);
282 nullDoubleClickInspector->setChecked(
false);
283 nullDoubleClickInspector->setEnabled(
false);
288 this, SLOT(selectDoubleClickInspector(QAction*)));
290 nullMoveInspector =
new QAction(
"<none>",
this);
291 nullMoveInspector->setCheckable(
true);
292 nullMoveInspector->setChecked(
false);
293 nullMoveInspector->setEnabled(
false);
298 this, SLOT(selectMoveInspector(QAction*)));
300 nullComparator =
new QAction(
"<none>",
this);
301 nullComparator->setCheckable(
true);
302 nullComparator->setChecked(
false);
303 nullComparator->setEnabled(
false);
308 this, SLOT(selectComparator(QAction*)));
310 solutionInspectorMenu =
new QMenu(
"Solution inspectors");
312 doubleClickInspectorMenu =
new QMenu(
"Double click inspectors");
313 doubleClickInspectorMenu->addActions(
315 moveInspectorMenu =
new QMenu(
"Move inspectors");
317 comparatorMenu =
new QMenu(
"Comparators");
322 this, SLOT(inspectWithAction(QAction*)));
325 this, SLOT(inspectBeforeFPWithAction(QAction*)));
327 inspectNodeMenu =
new QMenu(
"Inspect");
328 inspectNodeMenu->addAction(
inspect);
329 connect(inspectNodeMenu, SIGNAL(aboutToShow()),
330 this, SLOT(populateInspectors()));
332 inspectNodeBeforeFPMenu =
new QMenu(
"Inspect before fixpoint");
334 connect(inspectNodeBeforeFPMenu, SIGNAL(aboutToShow()),
335 this, SLOT(populateInspectors()));
336 populateInspectors();
338 contextMenu =
new QMenu(
this);
339 contextMenu->addMenu(inspectNodeMenu);
340 contextMenu->addMenu(inspectNodeBeforeFPMenu);
344 contextMenu->addAction(
center);
346 contextMenu->addSeparator();
351 contextMenu->addSeparator();
360 contextMenu->addSeparator();
362 contextMenu->addMenu(bookmarksMenu);
363 contextMenu->addAction(
setPath);
366 contextMenu->addSeparator();
368 contextMenu->addMenu(doubleClickInspectorMenu);
369 contextMenu->addMenu(solutionInspectorMenu);
370 contextMenu->addMenu(moveInspectorMenu);
372 connect(autoZoomButton, SIGNAL(toggled(
bool)), canvas,
375 connect(canvas, SIGNAL(autoZoomChanged(
bool)),
376 autoZoomButton, SLOT(setChecked(
bool)));
398 layout->addWidget(scrollArea, 0,0,-1,1);
399 layout->addWidget(canvas->
scaleBar, 1,1, Qt::AlignHCenter);
400 layout->addWidget(autoZoomButton, 0,1, Qt::AlignHCenter);
409 QMetaObject::connectSlotsByName(
this);
413 Gist::resizeEvent(QResizeEvent*) {
418 Gist::addInspector(
Inspector* i0, QAction*& nas, QAction*& nad,
421 actions().indexOf(nullDoubleClickInspector) != -1) {
430 nas =
new QAction(i0->
name().c_str(),
this);
431 nas->setCheckable(
true);
433 solutionInspectorMenu->clear();
436 nad =
new QAction(i0->
name().c_str(),
this);
437 nad->setCheckable(
true);
439 doubleClickInspectorMenu->clear();
440 doubleClickInspectorMenu->addActions(
443 nam =
new QAction(i0->
name().c_str(),
this);
444 nam->setCheckable(
true);
446 moveInspectorMenu->clear();
447 moveInspectorMenu->addActions(
450 QAction* ia =
new QAction(i0->
name().c_str(),
this);
452 QAction* ibfpa =
new QAction(i0->
name().c_str(),
this);
456 ia->setShortcut(QKeySequence(QString(
"Ctrl+")+
458 ibfpa->setShortcut(QKeySequence(QString(
"Ctrl+Alt+")+
469 actions().indexOf(nullDoubleClickInspector) == -1) {
471 for (
int i=0;
i<is.
size();
i++) {
473 is[
i]->setChecked(
false);
477 nas->setChecked(
true);
478 selectSolutionInspector(nas);
487 actions().indexOf(nullDoubleClickInspector) == -1) {
489 for (
int i=0;
i<is.
size();
i++) {
491 is[
i]->setChecked(
false);
495 nad->setChecked(
true);
496 selectDoubleClickInspector(nad);
505 actions().indexOf(nullDoubleClickInspector) == -1) {
507 for (
int i=0;
i<is.
size();
i++) {
509 is[
i]->setChecked(
false);
513 nam->setChecked(
true);
514 selectMoveInspector(nam);
521 for (
int i=0;
i<is.
size();
i++) {
523 is[
i]->setChecked(
false);
530 QAction* ncs =
new QAction(c->
name().c_str(),
this);
531 ncs->setCheckable(
true);
533 comparatorMenu->clear();
535 ncs->setChecked(
true);
536 selectComparator(ncs);
539 Gist::~Gist(
void) {
delete canvas; }
542 Gist::on_canvas_contextMenu(QContextMenuEvent* event) {
543 contextMenu->popup(event->globalPos());
547 Gist::on_canvas_statusChanged(VisualNode* n,
const Statistics& stats,
549 nodeStatInspector->
node(*canvas->
na,n,stats,finished);
558 stop->setEnabled(
true);
559 reset->setEnabled(
false);
560 navUp->setEnabled(
false);
577 center->setEnabled(
false);
580 print->setEnabled(
false);
587 stop->setEnabled(
false);
588 reset->setEnabled(
true);
590 if ( (n->isOpen() || n->hasOpenChildren()) && (!n->isHidden()) ) {
597 if (n->getNumberOfChildren() > 0) {
612 n->getStatus() ==
UNSTOP);
631 VisualNode* p = n->getParent(*canvas->
na);
635 navUp->setEnabled(
false);
639 navUp->setEnabled(
true);
640 unsigned int alt = n->getAlternative(*canvas->
na);
641 navRight->setEnabled(alt + 1 < p->getNumberOfChildren());
645 VisualNode* root = n;
646 while (!root->isRoot())
647 root = root->getParent(*canvas->
na);
648 NextSolCursor nsc(n,
false, *canvas->
na);
649 PreorderNodeVisitor<NextSolCursor> nsv(nsc);
651 navNextSol->setEnabled(nsv.getCursor().node() != root);
653 NextSolCursor psc(n,
true, *canvas->
na);
654 PreorderNodeVisitor<NextSolCursor> psv(psc);
656 navPrevSol->setEnabled(psv.getCursor().node() != root);
661 print->setEnabled(
true);
673 Gist::inspectWithAction(QAction*
a) {
678 Gist::inspectBeforeFPWithAction(QAction* a) {
689 Gist::selectDoubleClickInspector(QAction* a) {
695 Gist::selectSolutionInspector(QAction* a) {
701 Gist::selectMoveInspector(QAction* a) {
707 Gist::selectComparator(QAction* a) {
712 Gist::selectBookmark(QAction* a) {
719 Gist::addBookmark(
const QString&
id) {
724 QAction* nb =
new QAction(
id,
this);
725 nb->setCheckable(
true);
730 Gist::removeBookmark(
int idx) {
739 Gist::populateBookmarksMenu(
void) {
740 bookmarksMenu->clear();
742 bookmarksMenu->addSeparator();
747 Gist::populateInspectors(
void) {
748 inspectNodeMenu->clear();
749 inspectNodeMenu->addAction(
inspect);
750 inspectNodeMenu->addSeparator();
752 inspectNodeBeforeFPMenu->clear();
754 inspectNodeBeforeFPMenu->addSeparator();
771 Gist::getSmoothScrollAndZoom(
void) {
775 Gist::setSmoothScrollAndZoom(
bool b) {
779 Gist::setRecompDistances(
int c_d,
int a_d) {
793 Gist::setShowCopies(
bool b) {
797 Gist::getShowCopies(
void) {
802 Gist::showStats(
void) {