Here is how the model for the view is defined and instantiated.
{
Q_OBJECT
public:
static CommunicationModel
* instance
(QWidget* parent
= 0);
QVariant headerData
(int section, Qt
::Orientation orientation,
int role
= Qt
::DisplayRole) const;
Qt::ItemFlags flags( const QModelIndex& ) const ;
bool addFrame(const Can_Frame &frame);
void clear();
void sort (int column, Qt::SortOrder order = Qt::AscendingOrder );
private:
CommunicationModel
(QObject *parent
= 0);
IdentifiersModel* id_model;
QList<Can_Frame> m_communication; // Communication log
};
class CommunicationModel : public QAbstractTableModel
{
Q_OBJECT
public:
static CommunicationModel* instance(QWidget* parent = 0);
int rowCount( const QModelIndex &index) const;
int columnCount( const QModelIndex &index) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags( const QModelIndex& ) const ;
bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex());
bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex());
bool addFrame(const Can_Frame &frame);
void clear();
void sort (int column, Qt::SortOrder order = Qt::AscendingOrder );
private:
CommunicationModel(QObject *parent = 0);
IdentifiersModel* id_model;
QList<Can_Frame> m_communication; // Communication log
};
To copy to clipboard, switch view to plain text mode
CommunicationView
::CommunicationView( QWidget* parent
) : PrintableTableView(parent)
{
m_model = CommunicationModel::instance(this);
setModel(m_model);
m_delegate = new CommunicationDelegate(this);
setItemDelegate(m_delegate);
CommunicationView::CommunicationView( QWidget* parent ) :
PrintableTableView(parent)
{
m_model = CommunicationModel::instance(this);
setModel(m_model);
m_delegate = new CommunicationDelegate(this);
setItemDelegate(m_delegate);
To copy to clipboard, switch view to plain text mode
.. and how I do instantiate my view ...
WidgetCommunication
::WidgetCommunication( QWidget* parent
) :{
// Title
title = new TitleFrame(this,"Communication log",true);
// Body
body = CommunicationView::instance(this);
// Status
quickSend = new QuickSend(this);
// Layout
mainLayout->addWidget(title);
mainLayout->addWidget(body);
mainLayout->addWidget(quickSend);
mainLayout->setContentsMargins (0, 0, 0, 0);
setLayout(mainLayout);
}
WidgetCommunication::WidgetCommunication( QWidget* parent ) :
QWidget( parent )
{
// Title
title = new TitleFrame(this,"Communication log",true);
// Body
body = CommunicationView::instance(this);
// Status
quickSend = new QuickSend(this);
// Layout
mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(title);
mainLayout->addWidget(body);
mainLayout->addWidget(quickSend);
mainLayout->setContentsMargins (0, 0, 0, 0);
setLayout(mainLayout);
}
To copy to clipboard, switch view to plain text mode
Bookmarks