QXRD  0.11.16
qcepsettingssaver.cpp
Go to the documentation of this file.
1 #include "qcepdebug.h"
2 #include "qcepmacros.h"
3 #include "qcepsettingssaver.h"
4 #include "qcepproperty.h"
5 #include <stdio.h>
6 #include "qcepmutexlocker.h"
7 #include <QThread>
8 
10  QObject(),
11  m_Owner(owner),
12  m_SaveDelay(5000)
13 {
15  printf("QcepSettingsSaver::QcepSettingsSaver(%p)\n", this);
16  }
17 
18  connect(&m_Timer, SIGNAL(timeout()), this, SLOT(performSave()));
19 }
20 
22 {
24  printf("QcepSettingsSaver::~QcepSettingsSaver(%p)\n", this);
25  }
26 }
27 
29 {
30  if (QThread::currentThread() != thread()) {
31  INVOKE_CHECK(QMetaObject::invokeMethod(this, "start"));
32  } else {
33  m_Timer.setSingleShot(false);
34 
35  m_Timer.start(m_SaveDelay);
36  }
37 }
38 
40 {
41  int nupdates = m_ChangeCount.fetchAndStoreOrdered(0);
42 
43  if (nupdates > 0) {
44  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
45 
46  if (qcepDebug(DEBUG_PREFS)) {
47  printMessage(tr("Settings Saver saving %1 updates").arg(nupdates));
48  }
49 
50  QTime tic;
51  tic.start();
52 
53  INVOKE_CHECK(QMetaObject::invokeMethod(m_Owner, "writeSettings", Qt::DirectConnection));
54 
55  if (qcepDebug(DEBUG_PREFS)) {
56  printMessage(tr("Saving settings took %1 msec").arg(tic.elapsed()));
57  }
58  }
59 }
60 
62 {
63  m_ChangeCount.fetchAndAddOrdered(1);
64 }
65 
66 void QcepSettingsSaver::printMessage(QString msg, QDateTime ts)
67 {
68  INVOKE_CHECK(QMetaObject::invokeMethod(m_Owner, "printMessage", Q_ARG(QString, msg), Q_ARG(QDateTime, ts)));
69 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QAtomicInt m_ChangeCount
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
#define INVOKE_CHECK(res)
Definition: qcepmacros.h:13
void changed(QcepProperty *prop=NULL)
QcepSettingsSaver(QObject *owner)