summaryrefslogtreecommitdiffstats
path: root/examples/graphicsview/anchorlayout
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-17 15:18:57 +0200
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-17 15:18:57 +0200
commit91d53f247c4615c8e5d3ea0cab0e3f494b46f6e5 (patch)
tree9a3dbe823527fed6de3f3336a9463f2fccdd2b10 /examples/graphicsview/anchorlayout
parent39e13f96004d520bb2124e1f7bf9ff8fcc04f6b8 (diff)
Clean up example
Diffstat (limited to 'examples/graphicsview/anchorlayout')
-rw-r--r--examples/graphicsview/anchorlayout/main.cpp74
-rw-r--r--examples/graphicsview/anchorlayout/noGUI.cpp83
2 files changed, 6 insertions, 151 deletions
diff --git a/examples/graphicsview/anchorlayout/main.cpp b/examples/graphicsview/anchorlayout/main.cpp
index ecb2675cc1..1c87fa0e31 100644
--- a/examples/graphicsview/anchorlayout/main.cpp
+++ b/examples/graphicsview/anchorlayout/main.cpp
@@ -3,24 +3,6 @@
#include <QGraphicsAnchorLayout>
#include <QtGui>
-//#define BENCHMARK_RUN 1
-#define CALLGRIND_DEBUG 1
-
-#if defined(BENCHMARK_RUN)
-
-// Callgrind command line:
-// valgrind --tool=callgrind --instr-atstart=no ./anchorlayout >/dev/null 2>&1
-
-#if defined(CALLGRIND_DEBUG)
-#include <valgrind/callgrind.h>
-#else
-#define CALLGRIND_START_INSTRUMENTATION do { } while (0)
-#define CALLGRIND_STOP_INSTRUMENTATION do { } while (0)
-#endif
-
-#endif
-
-
static QGraphicsProxyWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
const QSizeF &preferred = QSize(150.0, 100.0),
const QSizeF &maximum = QSizeF(200.0, 100.0),
@@ -36,34 +18,12 @@ static QGraphicsProxyWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 10
return w;
}
-class Test : public QObject
-{
- Q_OBJECT;
-public:
- Test(QGraphicsWidget *wi, QGraphicsLayout* la)
- : QObject(), w(wi), l(la), first(true) {}
-
- QGraphicsWidget *w;
- QGraphicsLayout *l;
- bool first;
-
-public slots:
- void onTimer() {
- if (first) {
- first = false;
- w->setContentsMargins(10, 10, 10, 10);
- } else {
- l->setContentsMargins(10, 10, 10, 10);
- }
- }
-};
-
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- QGraphicsScene *scene = new QGraphicsScene();
- scene->setSceneRect(0, 0, 800, 480);
+ QGraphicsScene scene;
+ scene.setSceneRect(0, 0, 800, 480);
QSizeF min(30, 100);
QSizeF pref(210, 100);
@@ -116,32 +76,10 @@ int main(int argc, char **argv)
l->anchor(l, QGraphicsAnchorLayout::Left, g, QGraphicsAnchorLayout::Left, 0);
l->anchor(f, QGraphicsAnchorLayout::Right, g, QGraphicsAnchorLayout::Right, 0);
-#ifdef BENCHMARK_RUN
- CALLGRIND_START_INSTRUMENTATION;
- for (int i = 0; i < 100; i++) {
- l->invalidate();
- l->d_ptr->calculateGraphs();
- }
- CALLGRIND_STOP_INSTRUMENTATION;
- return 0;
-#endif
-
- scene->addItem(w);
- scene->setBackgroundBrush(Qt::darkGreen);
- QGraphicsView *view = new QGraphicsView(scene);
+ scene.addItem(w);
+ scene.setBackgroundBrush(Qt::darkGreen);
+ QGraphicsView *view = new QGraphicsView(&scene);
view->show();
- Test test(w, l);
- QTimer timer;
- test.connect(&timer, SIGNAL(timeout()), SLOT(onTimer()));
- timer.start(5000);
-
- int rc = app.exec();
-
- delete scene;
- delete view;
-
- return rc;
+ return app.exec();
}
-
-#include "main.moc"
diff --git a/examples/graphicsview/anchorlayout/noGUI.cpp b/examples/graphicsview/anchorlayout/noGUI.cpp
deleted file mode 100644
index 3f04f9a295..0000000000
--- a/examples/graphicsview/anchorlayout/noGUI.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <QGraphicsWidget>
-#include "qgraphicsanchorlayout.h"
-
-// DEBUG
-#include "qgraphicsanchorlayout_p.h"
-
-static QGraphicsWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
- const QSizeF &preferred = QSize(150.0, 100.0),
- const QSizeF &maximum = QSizeF(200.0, 100.0))
-{
- QGraphicsWidget *w = new QGraphicsWidget;
- w->setMinimumSize(minimum);
- w->setPreferredSize(preferred);
- w->setMaximumSize(maximum);
- return w;
-}
-
-
-int main(int argc, char **argv)
-{
- Q_UNUSED(argc);
- Q_UNUSED(argv);
-
-
- QGraphicsWidget *a = createItem(QSizeF(50.0, 100.0),
- QSizeF(70.0, 100.0),
- QSizeF(100.0, 200.0));
- a->setData(0, "A");
-
- QGraphicsWidget *b = createItem(QSizeF(10.0, 100.0),
- QSizeF(20.0, 100.0),
- QSizeF(40.0, 200.0));
- b->setData(0, "B");
-
- QGraphicsWidget *c = createItem(QSizeF(50.0, 100.0),
- QSizeF(70.0, 100.0),
- QSizeF(100.0, 200.0));
- c->setData(0, "C");
-
- QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
-
- l->anchor(l, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Top);
- l->anchor(a, QGraphicsAnchorLayout::Bottom, b, QGraphicsAnchorLayout::Top);
- l->anchor(b, QGraphicsAnchorLayout::Bottom, c, QGraphicsAnchorLayout::Top);
- l->anchor(c, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom);
-
- l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left);
- l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Right);
- l->anchor(b, QGraphicsAnchorLayout::Left, c, QGraphicsAnchorLayout::Left);
- l->anchor(c, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right);
-
- l->dumpGraph();
-
- QSizeF layoutMinimumSize = l->effectiveSizeHint(Qt::MinimumSize);
- QSizeF layoutMaximumSize = l->effectiveSizeHint(Qt::MaximumSize);
- QSizeF layoutPreferredSize = l->effectiveSizeHint(Qt::PreferredSize);
-
-
- qWarning() << "Layout Min/Pref/Max: " << layoutMinimumSize
- << " " << layoutPreferredSize
- << " " << layoutMaximumSize;
-
-
- qWarning() << "\nSetting minimum size";
- l->setGeometry(QRectF(QPointF(0,0), layoutMinimumSize));
- qWarning() << "A: " << a->geometry();
- qWarning() << "B: " << b->geometry();
- qWarning() << "C: " << c->geometry();
-
- qWarning() << "\nSetting maximum size";
- l->setGeometry(QRectF(QPointF(0,0), layoutMaximumSize));
- qWarning() << "A: " << a->geometry();
- qWarning() << "B: " << b->geometry();
- qWarning() << "C: " << c->geometry();
-
- qWarning() << "\nSetting size 85.0";
- l->setGeometry(QRectF(QPointF(0,0), QSizeF(85.0, 200.0)));
- qWarning() << "A: " << a->geometry();
- qWarning() << "B: " << b->geometry();
- qWarning() << "C: " << c->geometry();
-
- return 0;
-}