-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmimodelo.cpp
More file actions
60 lines (53 loc) · 1.41 KB
/
mimodelo.cpp
File metadata and controls
60 lines (53 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "mimodelo.h"
#include <ctime>
#include <QDebug>
MiModelo::MiModelo(QObject *parent):QAbstractTableModel(parent)
{
filas =4;
columnas = 4;
srand (time(NULL));
for (int i = 0;i<filas;i++)
{
for (int j=0;j<columnas;j++)
{
int datonum = 48 + (std::rand()%(57-48+1));
int datoletra = 65 + (std::rand()%(90-65+1));
int dato = (0+(std::rand()%2)==0)?datonum:datoletra;
m_datos[i][j]=static_cast<QChar>(dato);
}
}
}
int MiModelo::columnCount(const QModelIndex &parent) const
{
return columnas;
}
QVariant MiModelo::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();
if (role == Qt::DisplayRole)
{
return QVariant(m_datos[index.row()][index.column()]);
}
return QVariant();
}
bool MiModelo::setData(const QModelIndex &index, const QVariant &value, int role)
{
m_datos[index.row()][index.column()]=static_cast<QChar>(value.toInt());
}
/*Qt::ItemFlags MiModelo::flags(const QModelIndex &index) const
{
if (!index.isValid())
{
return 0;
}
if (index.column()==2)
{
//return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
return QAbstractTableModel::flags(index) ^ Qt::ItemIsSelectable;
}
return QAbstractTableModel::flags(index);
}*/
int MiModelo::rowCount(const QModelIndex &parent) const
{
return filas;
}