Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
Executable
+114
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
*
|
||||
* TableModel for dynamic topics
|
||||
*
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QVector>
|
||||
#include <QSharedPointer>
|
||||
#include <QDomDocument>
|
||||
|
||||
#include <dds/dds.hpp>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
class SampleSortModel;
|
||||
class DetailViewDlg;
|
||||
|
||||
class SampleModel final : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SampleModel(QObject *parent = nullptr);
|
||||
~SampleModel();
|
||||
|
||||
enum Column
|
||||
{
|
||||
TypeName = 0,
|
||||
TopicName = 1,
|
||||
Description = 2,
|
||||
Pause = 3,
|
||||
Maximum = Pause
|
||||
};
|
||||
|
||||
struct SampleData
|
||||
{
|
||||
std::string typeName;
|
||||
QString topicName;
|
||||
QString description;
|
||||
int pause = 1000;
|
||||
QSharedPointer<dds::core::xtypes::DynamicData> legatusData;
|
||||
DetailViewDlg *dialog = nullptr;
|
||||
void toXml(QDomDocument &doc, QDomElement &elem) const;
|
||||
bool fromXml(QDomElement &elem);
|
||||
|
||||
QByteArray encodeForMime() const;
|
||||
static SampleData decodeFromMime(const QByteArray &encodedData);
|
||||
};
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole) override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
std::string typeName(const QModelIndex &index) const;
|
||||
const QSharedPointer<dds::core::xtypes::DynamicData> dynamicData(const QModelIndex &index) const;
|
||||
QString name(const QModelIndex &index) const;
|
||||
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
Qt::DropActions supportedDragActions() const override;
|
||||
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||
QStringList mimeTypes() const override;
|
||||
|
||||
bool addRow(const dds::core::xtypes::DynamicData &data, const QString &topicName, const QString &description = QString());
|
||||
bool deleteRow(const QModelIndex &index);
|
||||
bool updateRow(const QModelIndex &index, const QSharedPointer<dds::core::xtypes::DynamicData> &data, const QString &topicName);
|
||||
bool addRow(const SampleData &sample, int position = -1);
|
||||
|
||||
SampleData sampleData(const QModelIndex &index) const;
|
||||
void setDialog(const QModelIndex &index, DetailViewDlg *dlg);
|
||||
QModelIndex indexByDialog(const DetailViewDlg *dlg) const;
|
||||
|
||||
public slots:
|
||||
void onClear();
|
||||
|
||||
private:
|
||||
|
||||
QVector<SampleData> m_data;
|
||||
NGL::INGLLogger &m_logger;
|
||||
|
||||
friend class SampleSortModel;
|
||||
};
|
||||
|
||||
class SampleSortModel final : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QSortFilterProxyModel::QSortFilterProxyModel;
|
||||
|
||||
void setCurrentRow(int row) { m_currentRow = row; emit headerDataChanged(Qt::Vertical, row, row);}
|
||||
int currentRow() { return m_currentRow >= rowCount() ? -1 : m_currentRow; }
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
void sort(int column, Qt::SortOrder order) override;
|
||||
protected:
|
||||
bool lessThan(const QModelIndex &left,
|
||||
const QModelIndex &right) const override;
|
||||
private:
|
||||
int m_currentRow = -1;
|
||||
|
||||
};
|
||||
Reference in new issue
Block a user