Hi,
I have done this so far...
TreeModel.h
#ifndef ADD_DEVICES_TREE_PROXY_MODEL_H
#define ADD_DEVICES_TREE_PROXY_MODEL_H
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>
{
Q_OBJECT
public:
AddDeviceTreeProxyModel
(QObject *parent
= 0);
~AddDeviceTreeProxyModel();
private:
class Private;
Private* const m_pPrivate;
};
#endif // ADD_DEVICES_TREE_PROXY_MODEL_H
#ifndef ADD_DEVICES_TREE_PROXY_MODEL_H
#define ADD_DEVICES_TREE_PROXY_MODEL_H
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>
class AddDeviceTreeProxyModel : public QAbstractItemModel
{
Q_OBJECT
public:
AddDeviceTreeProxyModel(QObject *parent = 0);
~AddDeviceTreeProxyModel();
QVariant data(const QModelIndex &index, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
private:
class Private;
Private* const m_pPrivate;
};
#endif // ADD_DEVICES_TREE_PROXY_MODEL_H
To copy to clipboard, switch view to plain text mode
TreeModel.cpp
#include "TreeModel.h"
#include <QStandardItem>
class AddDeviceTreeProxyModel::Private
{
public:
// Constructor.
Private( AddDeviceTreeProxyModel* deviceTree )
: m_AddDeviceTreeProxyModel(deviceTree)
{
}
void setupModelData();
QMultiMap <QString, QString> m_ManufacturerModel;
// Multimap of Manufacturer and Model. QMultiMap <QString, QString> m_ModelBand;
// Multimap of Model and band.
private:
AddDeviceTreeProxyModel* const m_AddDeviceTreeProxyModel;
};
AddDeviceTreeProxyModel
::AddDeviceTreeProxyModel(QObject *parent
) m_pPrivate( new Private( this ))
{
for (int i = 0; i < 5 ; ++i)
{
m_pPrivate->m_manufacturerList.append(tr("Manf%1").arg(i));
}
for (int i = 0; i < m_pPrivate->m_manufacturerList.count() ; ++i)
{
m_pPrivate->m_ManufacturerModel.insert(tr("Manf%1").arg(i), "Model1");
m_pPrivate->m_ManufacturerModel.insert(tr("Manf%1").arg(i), "Model2");
}
for (int i = 0; i < m_pPrivate->m_manufacturerList.count() ; ++i)
{
m_pPrivate->m_ModelBand.insert(tr("Model1").arg(i), "Band1");
m_pPrivate->m_ModelBand.insert(tr("Model1").arg(i), "Band2");
m_pPrivate->m_ModelBand.insert(tr("Model2").arg(i), "Band1");
m_pPrivate->m_ModelBand.insert(tr("Model2").arg(i), "Band2");
}
m_pPrivate->setupModelData();
}
AddDeviceTreeProxyModel::~AddDeviceTreeProxyModel()
{
delete m_pPrivate;
}
int AddDeviceTreeProxyModel
::columnCount(const QModelIndex &parent
) const {
return 0;
}
{
}
Qt
::ItemFlags AddDeviceTreeProxyModel
::flags(const QModelIndex &index
) const{
return Qt::ItemIsEditable;
}
{
}
{
}
int AddDeviceTreeProxyModel
::rowCount(const QModelIndex &parent
) const {
return 0;
}
void AddDeviceTreeProxyModel::Private::setupModelData()
{
}
#include "TreeModel.h"
#include <QStandardItem>
class AddDeviceTreeProxyModel::Private
{
public:
// Constructor.
Private( AddDeviceTreeProxyModel* deviceTree )
: m_AddDeviceTreeProxyModel(deviceTree)
{
}
void setupModelData();
QStringList m_manufacturerList; // Manufacturer List.
QMultiMap <QString, QString> m_ManufacturerModel; // Multimap of Manufacturer and Model.
QMultiMap <QString, QString> m_ModelBand; // Multimap of Model and band.
private:
AddDeviceTreeProxyModel* const m_AddDeviceTreeProxyModel;
};
AddDeviceTreeProxyModel::AddDeviceTreeProxyModel(QObject *parent)
: QAbstractItemModel(parent),
m_pPrivate( new Private( this ))
{
for (int i = 0; i < 5 ; ++i)
{
m_pPrivate->m_manufacturerList.append(tr("Manf%1").arg(i));
}
for (int i = 0; i < m_pPrivate->m_manufacturerList.count() ; ++i)
{
m_pPrivate->m_ManufacturerModel.insert(tr("Manf%1").arg(i), "Model1");
m_pPrivate->m_ManufacturerModel.insert(tr("Manf%1").arg(i), "Model2");
}
for (int i = 0; i < m_pPrivate->m_manufacturerList.count() ; ++i)
{
m_pPrivate->m_ModelBand.insert(tr("Model1").arg(i), "Band1");
m_pPrivate->m_ModelBand.insert(tr("Model1").arg(i), "Band2");
m_pPrivate->m_ModelBand.insert(tr("Model2").arg(i), "Band1");
m_pPrivate->m_ModelBand.insert(tr("Model2").arg(i), "Band2");
}
m_pPrivate->setupModelData();
}
AddDeviceTreeProxyModel::~AddDeviceTreeProxyModel()
{
delete m_pPrivate;
}
int AddDeviceTreeProxyModel::columnCount(const QModelIndex &parent) const
{
return 0;
}
QVariant AddDeviceTreeProxyModel::data(const QModelIndex &index, int role) const
{
return QVariant();
}
Qt::ItemFlags AddDeviceTreeProxyModel::flags(const QModelIndex &index) const
{
return Qt::ItemIsEditable;
}
QModelIndex AddDeviceTreeProxyModel::index(int row, int column, const QModelIndex &parent) const
{
return QModelIndex();
}
QModelIndex AddDeviceTreeProxyModel::parent(const QModelIndex &index) const
{
return QModelIndex();
}
int AddDeviceTreeProxyModel::rowCount(const QModelIndex &parent) const
{
return 0;
}
void AddDeviceTreeProxyModel::Private::setupModelData()
{
}
To copy to clipboard, switch view to plain text mode
Main.cpp
#include <QApplication>
#include "TreeModel.h"
#include "ui_Form.h"
int main(int argc, char** argv)
{
Ui::Form ui;
ui.setupUi(&form);
form.show();
AddDeviceTreeProxyModel model;
ui.listView->setModel( &model );
ui.treeView->setModel( &model );
return a.exec();
}
#include <QApplication>
#include "TreeModel.h"
#include "ui_Form.h"
int main(int argc, char** argv)
{
QApplication a(argc, argv);
QWidget form;
Ui::Form ui;
ui.setupUi(&form);
form.show();
AddDeviceTreeProxyModel model;
ui.listView->setModel( &model );
ui.treeView->setModel( &model );
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Please tell me how do i implement rowCount(), columnCount(), index(), parent() functions....
I am stuck... badly
Regards,
GK
Bookmarks