mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 00:25:35 +08:00
refs #432 Originator aware utility class
This commit is contained in:
35
src/blackmisc/originatoraware.cpp
Normal file
35
src/blackmisc/originatoraware.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* swift Project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "originatoraware.h"
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
COriginator COriginatorAware::getCurrentTimestampOriginator() const
|
||||||
|
{
|
||||||
|
COriginator o(m_originator);
|
||||||
|
o.setCurrentUtcTime();
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
COriginatorAware::COriginatorAware(QObject *object) : m_originator(object->objectName())
|
||||||
|
{
|
||||||
|
// if the object name changes we update our origiginator
|
||||||
|
this->m_originatorConnection = QObject::connect(object, &QObject::objectNameChanged, [this, object]()
|
||||||
|
{
|
||||||
|
this->m_originator = COriginator(object->objectName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
COriginatorAware::~COriginatorAware()
|
||||||
|
{
|
||||||
|
QObject::disconnect(m_originatorConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // ns
|
||||||
51
src/blackmisc/originatoraware.h
Normal file
51
src/blackmisc/originatoraware.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* swift Project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLACKMISC_ORIGINATORAWARE_H
|
||||||
|
#define BLACKMISC_ORIGINATORAWARE_H
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#include "blackmiscexport.h"
|
||||||
|
#include "originator.h"
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace BlackMisc
|
||||||
|
{
|
||||||
|
//! Value object encapsulating information about the originiator
|
||||||
|
class BLACKMISC_EXPORT COriginatorAware
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Get originator
|
||||||
|
const COriginator &originator() const { return m_originator; }
|
||||||
|
|
||||||
|
//! Originator with current timestamp
|
||||||
|
COriginator getCurrentTimestampOriginator() const;
|
||||||
|
|
||||||
|
//! My originator?
|
||||||
|
bool isMyOriginator(const COriginator &otherOriginator) { return m_originator == otherOriginator; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! Use literal based originator name
|
||||||
|
COriginatorAware(const QString &originatorName) : m_originator(originatorName) {}
|
||||||
|
|
||||||
|
//! Connect with QObject providing then name
|
||||||
|
COriginatorAware(QObject *nameProvider);
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
~COriginatorAware();
|
||||||
|
|
||||||
|
private:
|
||||||
|
COriginator m_originator;
|
||||||
|
QMetaObject::Connection m_originatorConnection;
|
||||||
|
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
Reference in New Issue
Block a user