Good evening,
So far did this:
Files .h
mainwindow.h
tarefaDelegate.h
tarefa.h
tarefaModel.h
tarefaWidget.h
Files .cpp
main.cpp
mainwindow.cpp
tarefaDelegate.cpp
tarefaModel.cpp
tarefaWidget.cpp
tarefa.cpp
Forms
mainwindow.ui
tarefaWidget.ui (picture below)
itemList.jpg
First want to make the Model. For now I have this
#ifndef TAREFAMODEL_H
#define TAREFAMODEL_H
#include <QAbstractListModel>
#include <tarefa.h>
#include <QList>
#include <QListView>
{
Q_OBJECT
public:
TarefaModel
(QList<Tarefa>
&tarefas,
QObject *parent
= 0)
private:
QList<Tarefa> listatarefas;
};
#endif // TAREFAMODEL_H
#ifndef TAREFAMODEL_H
#define TAREFAMODEL_H
#include <QAbstractListModel>
#include <tarefa.h>
#include <QList>
#include <QListView>
class TarefaModel : public QAbstractListModel
{
Q_OBJECT
public:
TarefaModel(QList<Tarefa> &tarefas, QObject *parent = 0)
: QAbstractListModel(parent), listatarefas(tarefas) {}
int rowCount(const QModelIndex &parent=QModelIndex() ) const;
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex());
bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex());
private:
QList<Tarefa> listatarefas;
};
#endif // TAREFAMODEL_H
To copy to clipboard, switch view to plain text mode
#include "tarefamodel.h"
#include <QTime>
#include <tarefa.h>
#include <QList>
int TarefaModel::rowCount(const QModelIndex& parent) const
{
return this->listatarefas.count();
}
{
if (!index.isValid())
if (index.row() >= listatarefas.size())
if (role == Qt::DisplayRole)
return listatarefas.at(index.row());
else
}
bool TarefaModel
::insertRows(int position,
int rows,
const QModelIndex &parent
) {
beginInsertRows
(QModelIndex(), position, position
+rows
-1);
for (int row = 0; row < rows; ++row) {
Tarefa *tarefa1 = new Tarefa("primeira tarefa");
listatarefas.insert(position, *tarefa1);
}
endInsertRows();
return true;
}
bool TarefaModel
::removeRows(int position,
int rows,
const QModelIndex &parent
) {
beginRemoveRows
(QModelIndex(), position, position
+rows
-1);
for (int row = 0; row < rows; ++row) {
listatarefas.removeAt(position);
}
endRemoveRows();
return true;
}
#include "tarefamodel.h"
#include <QTime>
#include <tarefa.h>
#include <QList>
int TarefaModel::rowCount(const QModelIndex& parent) const
{
return this->listatarefas.count();
}
QVariant TarefaModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() >= listatarefas.size())
return QVariant();
if (role == Qt::DisplayRole)
return listatarefas.at(index.row());
else
return QVariant();
}
bool TarefaModel::insertRows(int position, int rows, const QModelIndex &parent)
{
beginInsertRows(QModelIndex(), position, position+rows-1);
for (int row = 0; row < rows; ++row) {
Tarefa *tarefa1 = new Tarefa("primeira tarefa");
listatarefas.insert(position, *tarefa1);
}
endInsertRows();
return true;
}
bool TarefaModel::removeRows(int position, int rows, const QModelIndex &parent)
{
beginRemoveRows(QModelIndex(), position, position+rows-1);
for (int row = 0; row < rows; ++row) {
listatarefas.removeAt(position);
}
endRemoveRows();
return true;
}
To copy to clipboard, switch view to plain text mode
Tarefa.h
#ifndef TAREFA_H
#define TAREFA_H
#include <QString>
using namespace std;
class Tarefa{
private:
public:
//construtor
};
#endif // TAREFA_H
#ifndef TAREFA_H
#define TAREFA_H
#include <QString>
using namespace std;
class Tarefa{
private:
QString name;
QString context;
QString project;
public:
//construtor
Tarefa(QString name);
void setName(QString name);
void setContext(QString context);
void setProject(QString project);
QString getName();
QString getContext();
QString getProjec();
};
#endif // TAREFA_H
To copy to clipboard, switch view to plain text mode
Is anything wrong?
thanks for all!
Bookmarks