Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_main_loop.cpp « qt_tstfrm - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9108b2ceb0d577e70470cf82649496e227b712af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "test_main_loop.hpp"

#include <QtCore/QTimer>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>

#include "../base/scope_guard.hpp"

#include "../std/cstring.hpp"

TestMainLoop::TestMainLoop(TestMainLoop::TRednerFn const & fn)
  : m_renderFn(fn)
{
}

void TestMainLoop::exec(char const * testName)
{
  char * buf = (char *)malloc(strlen(testName) + 1);
  MY_SCOPE_GUARD(argvFreeFun, [&buf](){ free(buf); });
  strcpy(buf, testName);

  int argc = 1;
  QApplication app(argc, &buf);
  QTimer::singleShot(3000, &app, SLOT(quit()));

  QWidget w;
  w.setWindowTitle(testName);
  w.show();
  w.installEventFilter(this);

  app.exec();
}

bool TestMainLoop::eventFilter(QObject * obj, QEvent * event)
{
  if (event->type() == QEvent::Paint)
  {
    m_renderFn(qobject_cast<QWidget *>(obj));
    return true;
  }

  return false;
}