Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
# Created by Christian Ehrlicher, SLSE, 2017-11-01
|
||||
#
|
||||
|
||||
SET(tmsr_SRCS
|
||||
table_model_symbol_renderer_base.cpp
|
||||
table_model_symbol_renderer_base.h
|
||||
table_model_symbol_renderer.h
|
||||
)
|
||||
NGL_ADD_LIBRARY2(WS AsbHelper STATIC ${tmsr_SRCS})
|
||||
NGL_TARGET_LINK_LIBRARIES(AsbHelper
|
||||
PUBLIC
|
||||
Qt5::Core
|
||||
PRIVATE
|
||||
Qt5::Gui
|
||||
AsbDataPluginInterface
|
||||
NGLLogger
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Helper class template to provide symbol rendering in QAbstractItemModels
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2017-11-01
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "table_model_symbol_renderer_base.h"
|
||||
|
||||
namespace AdvancedSymbology
|
||||
{
|
||||
template <typename SUPER>
|
||||
class TableModelSymbolRenderer : public TableModelSymbolRendererBase
|
||||
{
|
||||
protected:
|
||||
using TableModelSymbolRendererBase::TableModelSymbolRendererBase;
|
||||
|
||||
virtual NGL::INGLLogger &logger() const final { return super()->m_logger; }
|
||||
virtual QAbstractItemModel *model() final { return super(); }
|
||||
virtual QModelIndex indexForId(int id, int column) final { return super()->findIndexForId(id, column); }
|
||||
SUPER *super() { return static_cast<SUPER *>(this); }
|
||||
const SUPER *super() const { return static_cast<const SUPER *>(this); }
|
||||
};
|
||||
|
||||
} // namespace AdvancedSymbology
|
||||
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Helper class to provide symbol rendering in QAbstractItemModels
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2017-11-01
|
||||
*/
|
||||
|
||||
|
||||
#include "table_model_symbol_renderer_base.h"
|
||||
|
||||
#include <AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QPointer>
|
||||
|
||||
namespace AdvancedSymbology
|
||||
{
|
||||
TableModelSymbolRendererBase::TableModelSymbolRendererBase(int iconColumn)
|
||||
: m_partyRole(AdvancedSymbology::Role::Unknown)
|
||||
, m_iconColumn(iconColumn)
|
||||
, m_super(nullptr)
|
||||
{}
|
||||
|
||||
void TableModelSymbolRendererBase::init(const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
|
||||
QObject *super)
|
||||
{
|
||||
m_asb = asb;
|
||||
m_super = super;
|
||||
}
|
||||
|
||||
void TableModelSymbolRendererBase::setDefaultRoleAndColor(const Role &role, const QColor &partyColor)
|
||||
{
|
||||
m_partyRole = role;
|
||||
m_partyColor = partyColor;
|
||||
}
|
||||
|
||||
QVariant TableModelSymbolRendererBase::decorationData(const QModelIndex &idx, int id) const
|
||||
{
|
||||
return decorationIcon(idx, id);
|
||||
}
|
||||
|
||||
QIcon TableModelSymbolRendererBase::decorationIcon(const QModelIndex &idx, int id) const
|
||||
{
|
||||
if (idx.column() != m_iconColumn)
|
||||
return QIcon();
|
||||
auto it = m_symbols.find(id);
|
||||
if (it != m_symbols.end())
|
||||
return it.value();
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
bool TableModelSymbolRendererBase::tryRenderSymbol(const QString &symbol, int id)
|
||||
{
|
||||
return tryRenderSymbol(symbol, id, m_partyColor, m_partyRole);
|
||||
}
|
||||
|
||||
bool TableModelSymbolRendererBase::tryRenderSymbol(const QString &symbol, int id, const QColor &color, Role role)
|
||||
{
|
||||
if (!m_asb || symbol.isEmpty())
|
||||
return false;
|
||||
AdvancedSymbology::SymbolDataToRender symDataToRender(symbol);
|
||||
symDataToRender.role = role;
|
||||
if (color.isValid())
|
||||
{
|
||||
symDataToRender.fillColor = color;
|
||||
symDataToRender.fillColorReplace = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// User-Defined Symbols (XML) need fillColor:
|
||||
symDataToRender.fillColor = AdvancedSymbology::SymbolDataToRender::unknownColor();
|
||||
symDataToRender.fillColorReplace = true;
|
||||
}
|
||||
|
||||
QSharedPointer<AdvancedSymbology::SymbolResult> sr = m_asb->findImage(symDataToRender);
|
||||
AdvancedSymbology::SymbolResult *ptrSr = sr.data();
|
||||
if (!ptrSr)
|
||||
{
|
||||
WARNING_LOG(logger()) << "Can not render symbol for sidc '" << symbol << "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
// already a request available?
|
||||
auto it = m_symbolResultMapping.find(ptrSr);
|
||||
if (it == m_symbolResultMapping.end())
|
||||
{
|
||||
SymbolResultData srd;
|
||||
srd.result = sr;
|
||||
srd.ids.push_back(id);
|
||||
m_symbolResultMapping.insert(ptrSr, srd);
|
||||
|
||||
if (ptrSr->isResultReady())
|
||||
{
|
||||
symbolRendered(ptrSr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// queued because the object is destroyed inside symbolRendered() due to QSharedPointer
|
||||
// works without this as an object because we look for ptrSr (which is a child of this,
|
||||
// see m_symbolResultMapping container)
|
||||
Q_ASSERT(m_super);
|
||||
QPointer<AdvancedSymbology::SymbolResult> qPointer(ptrSr);
|
||||
QObject::connect(ptrSr,
|
||||
&AdvancedSymbology::SymbolResult::resultReadyInternal,
|
||||
m_super ? m_super : ptrSr,
|
||||
[this, qPointer]() { symbolRendered(qPointer); }, Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SymbolResultData &srd = it.value();
|
||||
srd.ids.push_back(id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TableModelSymbolRendererBase::removeRenderedSymbol(int id)
|
||||
{
|
||||
m_symbols.remove(id);
|
||||
}
|
||||
|
||||
void TableModelSymbolRendererBase::symbolRendered(AdvancedSymbology::SymbolResult *sr)
|
||||
{
|
||||
if (!sr || !sr->isResultReady())
|
||||
return;
|
||||
|
||||
auto it = m_symbolResultMapping.constFind(sr);
|
||||
if (it == m_symbolResultMapping.constEnd())
|
||||
return;
|
||||
|
||||
const SymbolResultData &srd = it.value();
|
||||
|
||||
const QIcon ico(QPixmap::fromImage(srd.result->symbolImage().image()));
|
||||
for (int id : srd.ids)
|
||||
{
|
||||
DEBUG_LOG(logger()) << "Symbol for id " << id << " ready";
|
||||
m_symbols[id] = ico;
|
||||
const QModelIndex idx = indexForId(id, m_iconColumn);
|
||||
if (idx.isValid())
|
||||
emit model()->dataChanged(idx, idx, {Qt::DecorationRole});
|
||||
}
|
||||
|
||||
m_symbolResultMapping.erase(it);
|
||||
}
|
||||
} // namespace AdvancedSymbology
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Helper class to provide symbol rendering in QAbstractItemModels
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2017-11-01
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <QColor>
|
||||
#include <QHash>
|
||||
#include <QIcon>
|
||||
#include <QSharedPointer>
|
||||
|
||||
class QAbstractItemModel;
|
||||
class QModelIndex;
|
||||
class QVariant;
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
class INGLLogger;
|
||||
}
|
||||
|
||||
namespace AdvancedSymbology
|
||||
{
|
||||
class SymbolResult;
|
||||
class ForeignDataInterface;
|
||||
enum class Role;
|
||||
|
||||
|
||||
|
||||
class TableModelSymbolRendererBase
|
||||
{
|
||||
protected:
|
||||
explicit TableModelSymbolRendererBase(int iconColumn);
|
||||
virtual ~TableModelSymbolRendererBase() = default;
|
||||
|
||||
void init(const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
|
||||
QObject *super);
|
||||
void setDefaultRoleAndColor(const Role &role, const QColor &partyColor);
|
||||
QColor defaultColor() const { return m_partyColor; }
|
||||
Role defaultRole() const { return m_partyRole; }
|
||||
|
||||
QVariant decorationData(const QModelIndex &idx, int id) const;
|
||||
QIcon decorationIcon(const QModelIndex &idx, int id) const;
|
||||
bool tryRenderSymbol(const QString &symbol, int id);
|
||||
bool tryRenderSymbol(const QString &symbol, int id, const QColor &color, Role role);
|
||||
void removeRenderedSymbol(int id);
|
||||
|
||||
private:
|
||||
void symbolRendered(AdvancedSymbology::SymbolResult *sr);
|
||||
|
||||
virtual NGL::INGLLogger &logger() const = 0;
|
||||
virtual QAbstractItemModel *model() = 0;
|
||||
virtual QModelIndex indexForId(int id, int column) = 0;
|
||||
|
||||
private:
|
||||
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asb;
|
||||
struct SymbolResultData
|
||||
{
|
||||
QSharedPointer<AdvancedSymbology::SymbolResult> result;
|
||||
QVector<int> ids;
|
||||
};
|
||||
QHash<AdvancedSymbology::SymbolResult *, SymbolResultData> m_symbolResultMapping;
|
||||
Role m_partyRole;
|
||||
QColor m_partyColor;
|
||||
const int m_iconColumn;
|
||||
// participantId
|
||||
QHash<int, QIcon> m_symbols;
|
||||
QObject *m_super; // class which derives us, needed for proper con
|
||||
};
|
||||
|
||||
|
||||
} // namespace AdvancedSymbology
|
||||
Reference in new issue
Block a user