Ok, I am a little lost now. I've done this:
#ifndef UEPEOPLEMODEL_H
#define UEPEOPLEMODEL_H
#include <QImage>
#include <QVariant>
#include <QStringList>
#include <QDebug>
#include <QHash>
#include <QByteArray>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQueryModel>
#include <QtSql/QSqlRecord>
#include <QModelIndex>
#include <QQuickImageProvider>
#include "../settings/uedefaults.h"
{
Q_OBJECT
public:
~UePeopleModel();
int role) const Q_DECL_OVERRIDE;
const QSize &requestedSize
);
public:
static const int UePersonNameRole=Qt::UserRole+1;
static const int UePersonImageRole=UePersonNameRole+1;
};
#endif // UEPEOPLEMODEL_H
#ifndef UEPEOPLEMODEL_H
#define UEPEOPLEMODEL_H
#include <QImage>
#include <QVariant>
#include <QStringList>
#include <QDebug>
#include <QHash>
#include <QByteArray>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQueryModel>
#include <QtSql/QSqlRecord>
#include <QModelIndex>
#include <QQuickImageProvider>
#include "../settings/uedefaults.h"
class UePeopleModel : public QSqlQueryModel, QQuickImageProvider
{
Q_OBJECT
public:
UePeopleModel(QObject *parent=0);
~UePeopleModel();
QVariant data(const QModelIndex &index,
int role) const Q_DECL_OVERRIDE;
QImage image(const QString &id) const;
QImage requestImage(const QString &id,
QSize *size,
const QSize &requestedSize);
public:
static const int UePersonNameRole=Qt::UserRole+1;
static const int UePersonImageRole=UePersonNameRole+1;
};
#endif // UEPEOPLEMODEL_H
To copy to clipboard, switch view to plain text mode
and implementation:
#include "uepeoplemodel.h"
UePeopleModel
::UePeopleModel(QObject* parent
) QQuickImageProvider(QQmlImageProviderBase::Image,
QQmlImageProviderBase::ForceAsynchronousImageLoading)
{
if(!QSqlDatabase::connectionNames().
contains(UePosDatabase
::UeDatabaseConnectionNames::DATABASE_CONNECTION_NAME_PEOPLE,
Qt::CaseInsensitive))
{
db
=QSqlDatabase::addDatabase(UePosDatabase
::DATABASE_DRIVER,
UePosDatabase::UeDatabaseConnectionNames::DATABASE_CONNECTION_NAME_PEOPLE);
} // if
db.setHostName(/*this->uePosSettings()->ueDbHostname()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_HOSTNAME);
db.setDatabaseName(/*this->uePosSettings()->ueDbName()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_NAME);
db.setUserName(/*this->uePosSettings()->ueDbUser()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_USERNAME);
db.setPassword(/*this->uePosSettings()->ueDbPassword()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_PASSWORD);
if(db.open())
{
this->setQuery(UePosDatabase::UeSqlQueries::UeTablePeople::SQL_QUERY_GET_ALL_PEOPLE,
db);
//this->ueGenerateRoleNames();
}
else
{
qDebug() << db.lastError().text();
}
} // default constructor
UePeopleModel::~UePeopleModel()
{
} // default destructor
int role) const
{
role);
if(value.isValid())
{
switch(role)
{
case UePeopleModel::UePersonNameRole:
{
return value.toString();
} // case
case UePeopleModel::UePersonImageRole:
{
return QString::number(index.
row());
} // case
default:
} // switch
} // if
return value;
} // data
{
int iRow=id.toInt();
} // image
const QSize &requestedSize
) {
*size = image.size();
return image;
} // requestImage
#include "uepeoplemodel.h"
UePeopleModel::UePeopleModel(QObject* parent)
: QSqlQueryModel(parent),
QQuickImageProvider(QQmlImageProviderBase::Image,
QQmlImageProviderBase::ForceAsynchronousImageLoading)
{
QSqlDatabase db;
if(!QSqlDatabase::connectionNames().contains(UePosDatabase::UeDatabaseConnectionNames::DATABASE_CONNECTION_NAME_PEOPLE,
Qt::CaseInsensitive))
{
db=QSqlDatabase::addDatabase(UePosDatabase::DATABASE_DRIVER,
UePosDatabase::UeDatabaseConnectionNames::DATABASE_CONNECTION_NAME_PEOPLE);
} // if
db.setHostName(/*this->uePosSettings()->ueDbHostname()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_HOSTNAME);
db.setDatabaseName(/*this->uePosSettings()->ueDbName()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_NAME);
db.setUserName(/*this->uePosSettings()->ueDbUser()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_USERNAME);
db.setPassword(/*this->uePosSettings()->ueDbPassword()*/UePosDatabase::UeDatabaseConnectionParameters::DATABASE_PASSWORD);
if(db.open())
{
this->setQuery(UePosDatabase::UeSqlQueries::UeTablePeople::SQL_QUERY_GET_ALL_PEOPLE,
db);
//this->ueGenerateRoleNames();
}
else
{
qDebug() << db.lastError().text();
}
} // default constructor
UePeopleModel::~UePeopleModel()
{
} // default destructor
QVariant UePeopleModel::data(const QModelIndex &index,
int role) const
{
QVariant value=QSqlQueryModel::data(index,
role);
if(value.isValid())
{
switch(role)
{
case UePeopleModel::UePersonNameRole:
{
return value.toString();
} // case
case UePeopleModel::UePersonImageRole:
{
return QString::number(index.row());
} // case
default:
value=QVariant();
} // switch
} // if
return value;
} // data
QImage UePeopleModel::image(const QString &id) const
{
int iRow=id.toInt();
} // image
QImage UePeopleModel::requestImage(const QString &id,
QSize *size,
const QSize &requestedSize)
{
QImage image=this->image(id);
*size = image.size();
return image;
} // requestImage
To copy to clipboard, switch view to plain text mode
Now what?
Bookmarks