Hi,
I've started a custom model for a treeview, the code for the model is as follows:
#include "dacantreemodel.h"
DACanTreeModel
::DACanTreeModel(QObject *parent
){
}
DACanTreeModel::~DACanTreeModel()
{
}
QModelIndex DACanTreeModel
::index( int row,
int column,
const QModelIndex
& parent
) const {
}
int DACanTreeModel
::rowCount(const QModelIndex &parent
) const {
return m_oTreeItems.count();
}
int DACanTreeModel
::columnCount(const QModelIndex &parent
) const {
return 4;
}
{
if (!index.isValid())
if( role != Qt::DisplayRole )
if(index.column() > 4 )
{
}
if( role == Qt::DisplayRole )
data = "Test";
return data;
}
QVariant DACanTreeModel
::headerData(int section, Qt
::Orientation orientation,
int role) const
{
if (role != Qt::DisplayRole)
if (orientation == Qt::Horizontal)
return m_Headers[section];
else
}
{
}
void DACanTreeModel::setHeaders( QStringList& headers )
{
m_Headers = headers;
}
void DACanTreeModel
::addData( QString strId
) {
CMessage* pMess = new CMessage();
m_oTreeItems.
insert( strId,
(QObject*)pMess
);
}
#include "dacantreemodel.h"
DACanTreeModel::DACanTreeModel(QObject *parent)
: QAbstractItemModel(parent)
{
}
DACanTreeModel::~DACanTreeModel()
{
}
QModelIndex DACanTreeModel::index( int row, int column, const QModelIndex& parent) const
{
return QModelIndex();
}
int DACanTreeModel::rowCount(const QModelIndex &parent) const
{
return m_oTreeItems.count();
}
int DACanTreeModel::columnCount(const QModelIndex &parent) const
{
return 4;
}
QVariant DACanTreeModel::data(const QModelIndex &index, int role) const
{
QVariant data;
if (!index.isValid())
return QVariant();
if( role != Qt::DisplayRole )
return QVariant();
if(index.column() > 4 )
{
return QVariant();
}
if( role == Qt::DisplayRole )
data = "Test";
return data;
}
QVariant DACanTreeModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
return m_Headers[section];
else
return QVariant();
}
QModelIndex DACanTreeModel::parent(const QModelIndex &index) const
{
return QModelIndex();
}
void DACanTreeModel::setHeaders( QStringList& headers )
{
m_Headers = headers;
}
void DACanTreeModel::addData( QString strId )
{
CMessage* pMess = new CMessage();
m_oTreeItems.insert( strId, (QObject*)pMess );
}
To copy to clipboard, switch view to plain text mode
I have a QTreeView which sets the model to the above. When I call addData I want an item to be added to the tree but nothing is happening, I guess I'm missing something here?
In the data function I'm just setting it to 'Test' just to see if this would appear. I have not implemented the index() or the parent() method yet. How do I get something to be put into the tree?
Regards,
Steve
Bookmarks