#include <QtGui/QTableView>
#include <QtGui/QHeaderView>
#include <QAbstractTableModel>
#include <QItemSelection>
#include <QObject>
#include <string>
#include <map>
#include <vector>
using namespace std;
{
Q_OBJECT
public:
A_model
(int rows,
int cols,
QObject *parent
=0);
//reimplemented
QVariant headerData
(int section, Qt
::Orientation orientation,
int role
) const;
virtual bool setHeaderData
(int section,Qt
::Orientation orientation,
const QVariant &value
);
bool insertColumns
(int column,
int count,
const QModelIndex &index
);
// custom functions
void set_cols(int cols) ;
void set_rows(int rows) ;
int M_ROWS, M_COLS, M_ROW, M_COL;
private:
QList< QPair<QString, QString> > listOfPairs;
vector<int> i_vector; //1
vector<long> l_vector; //2
vector<float> f_vector; //3
vector<double> d_vector; //4
vector<std::string> s_vector; //5
mutable map<unsigned int,map<unsigned int,char> > map__type;
mutable map<unsigned int,map<unsigned int,unsigned int> > map_index;
mutable map<unsigned int,map<unsigned int,char> >::iterator map__type_i1;
mutable map<unsigned int,char>::iterator map__type_i2;
vector<string> vecHheader;
vector<string> vecVheader;
};
#include <QtGui/QTableView>
#include <QtGui/QHeaderView>
#include <QAbstractTableModel>
#include <QItemSelection>
#include <QObject>
#include <string>
#include <map>
#include <vector>
using namespace std;
class A_model : public QAbstractTableModel
{
Q_OBJECT
public:
A_model(int rows, int cols, QObject *parent=0);
//reimplemented
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual bool setHeaderData(int section,Qt::Orientation orientation,const QVariant &value);
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole);
bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex());
bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex());
bool insertColumns(int column, int count, const QModelIndex &index);
// custom functions
void set_cols(int cols) ;
void set_rows(int rows) ;
int M_ROWS, M_COLS, M_ROW, M_COL;
private:
QList< QPair<QString, QString> > listOfPairs;
vector<int> i_vector; //1
vector<long> l_vector; //2
vector<float> f_vector; //3
vector<double> d_vector; //4
vector<std::string> s_vector; //5
mutable map<unsigned int,map<unsigned int,char> > map__type;
mutable map<unsigned int,map<unsigned int,unsigned int> > map_index;
mutable map<unsigned int,map<unsigned int,char> >::iterator map__type_i1;
mutable map<unsigned int,char>::iterator map__type_i2;
vector<string> vecHheader;
vector<string> vecVheader;
};
To copy to clipboard, switch view to plain text mode
{
if (!index.isValid())
if (index.row() >= M_ROWS || index.row() < 0)
if (role == Qt::DisplayRole) {
unsigned int rr=(unsigned int)(index.row());
unsigned int cc=(unsigned int)(index.column());
switch (map__type[rr][cc])
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
return W_utiles
().
To_qstring(map_index
[rr
][cc
])+" "+ QString().
fromStdString(s_vector.
at(map_index
[rr
][cc
]));
break;
}
}
QVariant A_model::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
{ return QVariant();}
if (index.row() >= M_ROWS || index.row() < 0)
{ return QVariant();}
if (role == Qt::DisplayRole) {
unsigned int rr=(unsigned int)(index.row());
unsigned int cc=(unsigned int)(index.column());
switch (map__type[rr][cc])
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
return W_utiles().To_qstring(map_index[rr][cc])+" "+ QString().fromStdString(s_vector.at(map_index[rr][cc]));
break;
}
}
To copy to clipboard, switch view to plain text mode
QVariant A_model
::headerData(int section, Qt
::Orientation orientation,
int role
) const ....
return vecHheader[section];
.....
QVariant A_model::headerData(int section, Qt::Orientation orientation, int role) const
....
return vecHheader[section];
.....
To copy to clipboard, switch view to plain text mode
(This is because I say I can use vector without problems but not map)
Bookmarks