Skip to content

Commit

Permalink
fix: Return Refrences to LogData instead of a copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishwaldo committed Jun 23, 2020
1 parent 706c467 commit 4225fac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions qt-openzwave/include/qt-openzwave/qtozwlog.h
Expand Up @@ -57,7 +57,7 @@ class QTOPENZWAVESHARED_EXPORT QTOZWLog : public QTOZWReplicaBase {
bool initilizeBase() override;
bool initilizeSource(QRemoteObjectHost *m_sourceNode) override;
bool initilizeReplica(QRemoteObjectNode *m_replicaNode) override;
QVector<QTOZWLog::QTOZW_LogEntry> getLogEntries();
const QVector<QTOZWLog::QTOZW_LogEntry> &getLogEntries();

public:
quint32 getLogCount() const;
Expand Down Expand Up @@ -113,7 +113,7 @@ class QTOPENZWAVESHARED_EXPORT QTOZWLogModel : public QAbstractTableModel {
void resetModel();
void logsPoppped(quint32 size);
private:
QTOZWLog::QTOZW_LogEntry getLogData(int) const;
const QTOZWLog::QTOZW_LogEntry getLogData(const int) const;
QTOZWLog *m_qtozwlog;
};

Expand Down
10 changes: 6 additions & 4 deletions qt-openzwave/source/qtozwlog.cpp
Expand Up @@ -164,9 +164,10 @@ bool QTOZWLog::syncroniseLogs()
}
}

QVector<QTOZWLog::QTOZW_LogEntry> QTOZWLog::getLogEntries() {
if (!this->isReady())
return QVector<QTOZW_LogEntry>();
const QVector<QTOZWLog::QTOZW_LogEntry> &QTOZWLog::getLogEntries() {
if (!this->isReady()) {
return this->m_logData;
}
if (this->getConnectionType() == ConnectionType::Type::Local)
{
return this->d_ptr_internal->m_logData;
Expand Down Expand Up @@ -301,13 +302,14 @@ QVariant QTOZWLogModel::headerData(int section, Qt::Orientation orientation, int
}
return QVariant();
}

Qt::ItemFlags QTOZWLogModel::flags(const QModelIndex &index) const {
if (!index.isValid())
return Qt::NoItemFlags;
return QAbstractTableModel::flags(index);
}

QTOZWLog::QTOZW_LogEntry QTOZWLogModel::getLogData(int pos) const {
const QTOZWLog::QTOZW_LogEntry QTOZWLogModel::getLogData(const int pos) const {
if (this->m_qtozwlog->getLogEntries().count() >= pos)
return this->m_qtozwlog->getLogEntries().at(pos+1);
qCWarning(logModel) << "Can't find LogEntry at " << pos << " size:" << this->m_qtozwlog->getLogEntries().count();
Expand Down
5 changes: 3 additions & 2 deletions qt-openzwave/source/qtozwlog_p.cpp
Expand Up @@ -124,6 +124,7 @@ void QTOZWLog_Internal::Write(OpenZWave::LogLevel _level, uint8 const _nodeId, c
le.s_time = QDateTime::currentDateTime();
le.s_level = qtozwlevel;
if (static_cast<quint32>(this->m_logData.size()) >= this->m_maxLogLength) {
qCDebug(logModel) << "popping Log Mesages";
this->m_logData.pop_front();
emit logLinesPopped(1);
}
Expand Down Expand Up @@ -155,6 +156,7 @@ quint32 QTOZWLog_Internal::getLogCount()
{
return this->m_logData.count();
};

bool QTOZWLog_Internal::syncroniseLogs()
{
qCDebug(logModel) << "QTOZWLog_Internal::syncroniseLogs() called";
Expand Down Expand Up @@ -189,12 +191,11 @@ void QTOZWLog_Internal::sendSyncLogsBatch()
qCDebug(logModel) << "QTOZWLog_Internal::sendSyncLogsBatch() Finished";
}



quint32 QTOZWLog_Internal::getLogBufSize() const
{
return this->m_maxLogLength;
}

void QTOZWLog_Internal::setLogBufSize(quint32 size) {
if (this->m_maxLogLength != size)
{
Expand Down

0 comments on commit 4225fac

Please sign in to comment.