~ubuntu-branches/ubuntu/oneiric/soqt/oneiric

« back to all changes in this revision

Viewing changes to src/Inventor/Qt/SoQt.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2009-03-01 11:41:00 UTC
  • mfrom: (1.1.4 upstream) (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090301114100-f4zz3n1oasa52fgk
Tags: 1.4.2~svn20090224-2
* Upload upstream SVN head version containing fixes to build with Coin 3
  (Closes: #515729, #515736, #515742).  Upstream indicated to me that
  SVN is stable enough to release.

* control: Update Standards-Version to 3.8.0; no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
238
238
#include <qevent.h>
239
239
#include <qapplication.h>
240
240
#include <qmetaobject.h>
 
241
#include <Inventor/C/threads/thread.h>
 
242
 
241
243
 
242
244
#ifdef Q_WS_X11
243
245
#include <X11/Xlib.h>
270
272
#include <Inventor/Qt/devices/spwinput_win32.h>
271
273
#endif // HAVE_WIN32_API
272
274
 
273
 
 
274
275
#include <Inventor/Qt/SoQtComponent.h>
 
276
#include <Inventor/Qt/SoQtSignalThread.h>
275
277
#include <Inventor/Qt/SoAny.h>
276
278
#include <Inventor/Qt/SoQtInternal.h>
277
 
 
 
279
#include <Inventor/Qt/SoQtImageReader.h>
278
280
#include <soqtdefs.h>
279
281
 
280
282
// *************************************************************************
291
293
QTimer * SoQtP::delaytimeouttimer = NULL;
292
294
SoQtP * SoQtP::slotobj = NULL;
293
295
bool SoQtP::didcreatemainwidget = FALSE;
 
296
SoQtImageReader * SoQtP::imagereader = NULL;
294
297
 
295
298
// *************************************************************************
296
299
 
331
334
 
332
335
int SoQtP::DEBUG_LISTMODULES = ENVVAR_NOT_INITED;
333
336
 
 
337
// these two are used to make SoQt thread safe (changing a scene graph
 
338
// from a separate thread won't make Qt go haywire).
 
339
unsigned long SoQtP::original_thread;
 
340
SoQtSignalThread * SoQtP::signalthread = NULL;
 
341
 
334
342
// *************************************************************************
335
343
 
336
344
// We're using the singleton pattern to create a single SoQtP object
340
348
SoQtP *
341
349
SoQtP::soqt_instance(void)
342
350
{
343
 
  if (!SoQtP::slotobj) { SoQtP::slotobj = new SoQtP; }
 
351
  if (!SoQtP::slotobj) { 
 
352
    SoQtP::slotobj = new SoQtP; 
 
353
#if defined(__COIN__) && defined(SOQT_SIGNAL_THREAD_ACTIVE)
 
354
    // store the thread SoQt::init() is called from, and start a signal thread to
 
355
    // handle scene graph changes from other threads
 
356
    SoQtP::original_thread = cc_thread_id();
 
357
    SoQtP::signalthread = new SoQtSignalThread();
 
358
    QObject::connect(SoQtP::signalthread, SIGNAL(triggerSignal()),
 
359
                     SoQtP::slotobj, SLOT(slot_sensorQueueChanged()));
 
360
    SoQtP::signalthread->start();
 
361
#endif // __COIN__
 
362
  }
 
363
  
 
364
#if HAVE_SBIMAGE_ADDREADIMAGECB
 
365
  if (!SoQtP::imagereader) {
 
366
    SoQtP::imagereader = new SoQtImageReader();
 
367
  }
 
368
#endif // HAVE_SBIMAGE_ADDREADIMAGECB
344
369
  return SoQtP::slotobj;
345
370
}
346
371
 
519
544
// This function gets called whenever something has happened to any of
520
545
// the sensor queues. It starts or reschedules a timer which will
521
546
// trigger when a sensor is ripe for plucking.
 
547
 
522
548
void
523
549
SoGuiP::sensorQueueChanged(void *)
524
550
{
 
551
#if defined(__COIN__) && defined(SOQT_SIGNAL_THREAD_ACTIVE)
 
552
  if (SoQtP::signalthread->isRunning() && (cc_thread_id() != SoQtP::original_thread)) {
 
553
    SoQtP::signalthread->trigger();
 
554
    return;
 
555
  }
 
556
#endif // __COIN__ && SOQT_SIGNAL_THREAD_ACTIVE
 
557
  SoQtP::soqt_instance()->slot_sensorQueueChanged();
 
558
}
 
559
 
 
560
void
 
561
SoQtP::slot_sensorQueueChanged(void)
 
562
{
525
563
  // We need three different mechanisms to interface Coin sensor
526
564
  // handling with Qt event handling, which are:
527
565
  //
622
660
// spaceball devices.)
623
661
class SoQtApplication : public QApplication {
624
662
public:
625
 
  SoQtApplication(int argc, char ** argv) : QApplication(argc, argv) { 
 
663
  SoQtApplication(int & argc, char ** argv) : QApplication(argc, argv) {
 
664
 
626
665
#ifdef HAVE_X11_AVAILABLE
627
666
    this->display = NULL;
628
667
#endif // HAVE_X11_AVAILABLE
707
746
void
708
747
SoQt::init(QWidget * toplevelwidget)
709
748
{
 
749
  // make sure the SoQtP slotinstance is initialized in the main thread
 
750
  SoQtP::soqt_instance();
 
751
 
710
752
  // workaround for Qt bug under Windows. See above for comments
711
753
  soqt_reset_simple_timers();
712
754
 
719
761
    // use a static char array to store the dummy argv parameters
720
762
    static char * dummyargv[1];
721
763
    dummyargv[0] = "SoQt";
722
 
    SoQtP::appobject = new SoQtApplication(1, (char **) dummyargv);
 
764
    int argc = 1;
 
765
    SoQtP::appobject = new SoQtApplication(argc, (char **) dummyargv);
723
766
    SoQtP::madeappobject = TRUE;
724
767
  }
725
768
  else {
806
849
QWidget *
807
850
SoQt::init(int & argc, char ** argv, const char * appname, const char * classname)
808
851
{
 
852
  // make sure the SoQtP instance is initialized in the main thread
 
853
  SoQtP::soqt_instance();
809
854
  // Must do this here so SoDebugError is initialized before it could
810
855
  // be attempted used.
811
856
  if (!SoDB::isInitialized()) { SoDB::init(); }
851
896
SoQt::mainLoop(void)
852
897
{
853
898
  (void) qApp->exec();
854
 
 
855
899
// Disabled invocation of SoQt::done(), since this calls SoDB::finish(), 
856
900
// which means we would run into issues doing the usual...
857
901
//    SoQt::mainLoop();
883
927
void
884
928
SoQt::done(void)
885
929
{
 
930
#if defined(__COIN__) && defined(SOQT_SIGNAL_THREAD_ACTIVE)
 
931
  SoQtP::signalthread->stopThread();
 
932
  SoQtP::signalthread->wait();
 
933
  delete SoQtP::signalthread;
 
934
  SoQtP::signalthread = NULL;
 
935
#endif //__COIN__ && SOQT_SIGNAL_THREAD_ACTIVE
 
936
  delete SoQtP::imagereader;
 
937
  SoQtP::imagereader = NULL;
 
938
 
886
939
  // To avoid getting any further invokations of
887
940
  // SoGuiP::sensorQueueChanged() (which would re-allocate the timers
888
941
  // we destruct below). This could for instance happen when