Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-20 Thread Mykola Vovchok

Hi,

I suggest to put fixed items in ListView header. It seems, it is simpler 
than C++ proxy model.

You could try something like this:

SilicaListView {

header: Column {
width: parent.width

PageHeader {
title: "Page Title"
}

Column {
width: parent.width

Repeater {
model: ["Today", "Overdue", "Completed", 
"Trash", "...", "..."]


ListItem {
height: Theme.itemSizeSmall

onClicked: {
// ...
}

Label {
anchors.verticalCenter: 
parent.verticalCenter

width: parent.width

text: modelData
}
}
}
}
}

delegate: ListItem {
height: Theme.itemSizeSmall

onClicked: {
// ...
}

Label {
anchors.verticalCenter: parent.verticalCenter
width: parent.width

text: model.dbValue
}
}


model: dbModel
}


___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org


Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-20 Thread Michael Fuchs



Am 20.04.2015 um 10:49 schrieb François K.:

Hi Michael, hi Lucien, hi devs,



I support this idea: Why don't you build a model that is built in
two step during creation, first, build the 6 entries, then build
the rest ?


Do you suggest to do this in C++ (which is my idea n°1) or mix C++
and QML (see below) ?



You are creating your custom Model in C++ holding your data, which you 
present in a View in QML, right?
Maybe you can derive another Model from your custom C++-Model which 
appends or inserts the fixed items.


FixedItemsModel.qml:

import com.daitheflu.custommodel 1.0

CustomModel {

  Component.onComplete {
   //this could be a place for doing some autostart stuff
  }
}


FirstPage.qml:

FixedItemsModel {
 id: projects
}
...

greets, Michael.
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-20 Thread Richard Grooff
Hi, 

In qml it would be something like this: 
> state = "Loaded"
>  for (var i = 0; i < xmlOverstapgegevens.count+6; i++) {
>   if (i<6)
> {// first we load the FixedValues
> // (use select case? )
> if (i=0){
>  list_model2.append({"StationVan"   :  "FixedValue1"
> }
> if (i=1){
>  list_model2.append({"StationVan"   :  "FixedValue2"
> }
> .
> .
> .
> .
> if (i=5){
>  list_model2.append({"StationVan"   :  "FixedValue6"
> }
>   }
>   else {// Then we load the dynamic values
> // don't forget to correct the counter for the FixedValues
> var item = get(i-6)
> list_model2.append({"StationVan"   :  item.StationVan
>   }

Don't use two step creation, it caused terrible timing issues for me. 

On Mon Apr 20 10:49:56 2015 GMT+0200, François K. wrote:
> Hi Michael, hi Lucien, hi devs,
> 
> 
> > I support this idea:
> > Why don't you build a model that is built in two step during
> > creation, first, build the 6 entries, then build the rest ?
> 
> Do you suggest to do this in C++ (which is my idea n°1) or mix C++ and QML 
> (see below) ?
> 
> 
> > > Is'nt it possible to add the items in the QML-part?
> 
> I don't know... I just don't know how to do this with QML :/
> With a SilicaListView, I guess Qt would overwrite the fixed items as soon as 
> I set the model property on the SilicaListView, wouldn't it ?
> 
> Cheers,
> 
> -- 
> François
> ___
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.or

-- 
Sent from my Jolla
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-20 Thread François K .
Hi Nils,

Wow, thanks *a lot* !

I totally overlooked the user of QAbstractProxyModel. This could definitely 
help if I choose n°1 idea.
I'd still have to figure out how to deal with the refreshing part, but that's a 
strong way to get started.

Thanks a lot, I wasn't asking for so much stuff/code :)

(Would you mind if I put your names in the credits (Lucien, Michael, Peter, 
Nils) ?)

-- 
François


- Mail original -
> Hi,
> 
> On Fri, Apr 17, 2015 at 12:09 PM, François K. 
> wrote:
> > 1/ The first one is to build a Model that would inherit from
> > QAbstractListModel.
> > In the constructor, I would add the first 6 items (hard-code them).
> 
> maybe this code can give you some inspiration to solve at least some
> part of your problem:
> 
> -- prefixmodel.h
> 
> #ifndef PREFIXMODEL_h
> #define PREFIXMODEL_h
> 
> #include 
> 
> class RealModel;
> 
> class PrefixModel : public QAbstractProxyModel
> {
>   Q_OBJECT
> 
> public:
> 
>   explicit PrefixModel(QObject *parent = 0);
> 
>   int rowCount(const QModelIndex &parent = QModelIndex()) const;
>   int columnCount(const QModelIndex &parent) const { return 1; }
>   QModelIndex parent(const QModelIndex &) const { return
>   QModelIndex(); }
>   QModelIndex index(int row, int column, const QModelIndex &parent =
> QModelIndex()) const;
> 
>   QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
>   QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
> 
>   void setRealModel(RealModel *sourceModel)
> 
> private slots:
> 
>   void sourceRowsInserted(const QModelIndex &, int, int);
>   void sourceRowsRemoved(const QModelIndex &, int, int);
>   void sourceRowsAboutToBeInserted(const QModelIndex &, int, int);
>   void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int);
>   void sourceReset();
>   QVariant data(const QModelIndex &proxyIndex, int role) const;
> };
> 
> #endif // PREFIXMODEL_h
> 
> -- prefixmodel.cpp
> 
> #include "prefixmodel.h"
> #incldue "realmodel.h"
> 
> #define FIX_ITEMS 6
> 
> PrefixModel::PrefixModel(QObject *parent) :
>   QAbstractProxyModel(parent)
> {
> }
> 
> QModelIndex PrefixModel::mapFromSource(const QModelIndex
> &sourceIndex) const
> {
>   return sourceModel()->index(sourceIndex.row() + FIX_ITEMS,
> sourceIndex.column());
> }
> 
> QModelIndex PrefixModel::mapToSource(const QModelIndex &proxyIndex)
> const
> {
>   if (!sourceModel())
> return QModelIndex();
> 
>   return sourceModel()->index(proxyIndex.row() - FIX_ITEMS,
> proxyIndex.column());
> }
> 
> QVariant PrefixModel::data(const QModelIndex &proxyIndex, int role)
> const
> {
>   if (proxyIndex.row() < FIX_ITEMS) {
> if (role == Qt::DisplayRole)
>   return QString("fix item #%1").arg(proxyIndex.row());
> 
> return QVariant();
>   }
>   return QAbstractProxyModel::data(proxyIndex, role);
> }
> 
> int PrefixModel::rowCount(const QModelIndex &parent) const
> {
>   if (!sourceModel())
> return 0;
> 
>   return sourceModel()->rowCount(parent) + FIX_ITEMS;
> }
> 
> QModelIndex PrefixModel::index(int row, int column, const QModelIndex
> &parent) const
> {
>   return createIndex(row, column, 0);
> }
> 
> void PrefixModel::setRealModel(RealModel *sourceModel)
> {
>   if (this->sourceModel() == sourceModel)
> return;
> 
>   if (this->sourceModel())
> this->sourceModel()->disconnect(this);
> 
>   QAbstractProxyModel::setSourceModel(sourceModel);
>   emit sourceModelChanged();
> 
>   connect(sourceModel,
> SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this,
> SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)));
>   connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
> this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
>   connect(sourceModel,
> SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this,
> SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
>   connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
>   this,
> SLOT(sourceRowsRemoved(QModelIndex,int,int)));
>   connect(sourceModel, SIGNAL(modelReset()), this,
>   SLOT(sourceReset()));
> }
> 
> RealModel *PrefixModel::sourceModelInternal() const
> {
>   return
>   qobject_cast(QAbstractProxyModel::sourceModel());
> }
> 
> void PrefixModel::sourceRowsInserted(const QModelIndex &, int start,
> int end)
> {
>   endInsertRows();
> }
> 
> void PrefixModel::sourceRowsRemoved(const QModelIndex &, int start,
> int end)
> {
>   endRemoveRows();
> }
> 
> void PrefixModel::sourceRowsAboutToBeInserted(const QModelIndex &,
> int
> start, int end)
> {
>   beginInsertRows(QModelIndex(), start + FIX_ITEMS, end + FIX_ITEMS);
> }
> 
> void PrefixModel::sourceRowsAboutToBeRemoved(const QModelIndex &, int
> start, int end)
> {
>   beginRemoveRows(QModelIndex(), start + FIX_ITEMS, end + FIX_ITEMS);
> }
> 
> void PrefixModel::sourceReset()
> {
>   beginResetModel();
>   endResetModel();
> }
> 
> Nils
> ___
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to
> de

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-20 Thread François K .
Hi Peter,

Thanks for your answer and your time :)


> I dont get it. A project status is a perfect field for a DB.
> The query would even group the project in the right way.
> 
> select status , projectname
>   from todolist
> group by statusRank
> ;

Currently, a task is represented that way :

uuid, description, status, due_date, project, [several others fields...]


A task *MUST* have a uuid, a description and a status (status being either 
'pending', 'completed', 'deleted').
A task *CAN* have a due_date and CAN have a project.

With this, I want the first item of my list to be "Today" (so the user can 
quickly access all the tasks he has to do today). When the user selects this 
item, he would get a list of all tasks for which due_date is set and equals 
today, regardless of the project field (the user would get tasks from project 
'Super project', 'House building', 'New server', and also tasks that don't have 
a project set.

The second item of the list would be "Overdue", and would list all tasks that 
have a due_date which is past "today", also regardless of the project field.

I have 6 fixed items like these.

Then, I want the user to be able to access his projects. So I'd like to list 
the existing projects (this is the dynamic part of the model) :
"Super project" would list all tasks that have the project field set to "Super 
project". In this case, I don't care about the due_date field. I just want the 
task belonging to this project.


> then you could have some code that goes through the objects
> print project { arraycontainer.projectname }
> If (arraycontainer[i+1].status <> arraycontainer[i].status) { print
> new_cat() };
> 
> sorry for the bad pseudocode but i hope you get the idea.my c++ is
> not good and i want to go to bed.

Nah, don't apologize, thank *you* for taking some time and trying to help me :)

Cheers,

-- 
François
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-20 Thread François K .
Hi Michael, hi Lucien, hi devs,


> I support this idea:
> Why don't you build a model that is built in two step during
> creation, first, build the 6 entries, then build the rest ?

Do you suggest to do this in C++ (which is my idea n°1) or mix C++ and QML (see 
below) ?


> > Is'nt it possible to add the items in the QML-part?

I don't know... I just don't know how to do this with QML :/
With a SilicaListView, I guess Qt would overwrite the fixed items as soon as I 
set the model property on the SilicaListView, wouldn't it ?

Cheers,

-- 
François
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-19 Thread Nils Jeisecke
Hi,

On Fri, Apr 17, 2015 at 12:09 PM, François K.  wrote:
> 1/ The first one is to build a Model that would inherit from 
> QAbstractListModel.
> In the constructor, I would add the first 6 items (hard-code them).

maybe this code can give you some inspiration to solve at least some
part of your problem:

-- prefixmodel.h

#ifndef PREFIXMODEL_h
#define PREFIXMODEL_h

#include 

class RealModel;

class PrefixModel : public QAbstractProxyModel
{
  Q_OBJECT

public:

  explicit PrefixModel(QObject *parent = 0);

  int rowCount(const QModelIndex &parent = QModelIndex()) const;
  int columnCount(const QModelIndex &parent) const { return 1; }
  QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
  QModelIndex index(int row, int column, const QModelIndex &parent =
QModelIndex()) const;

  QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
  QModelIndex mapToSource(const QModelIndex &proxyIndex) const;

  void setRealModel(RealModel *sourceModel)

private slots:

  void sourceRowsInserted(const QModelIndex &, int, int);
  void sourceRowsRemoved(const QModelIndex &, int, int);
  void sourceRowsAboutToBeInserted(const QModelIndex &, int, int);
  void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int);
  void sourceReset();
  QVariant data(const QModelIndex &proxyIndex, int role) const;
};

#endif // PREFIXMODEL_h

-- prefixmodel.cpp

#include "prefixmodel.h"
#incldue "realmodel.h"

#define FIX_ITEMS 6

PrefixModel::PrefixModel(QObject *parent) :
  QAbstractProxyModel(parent)
{
}

QModelIndex PrefixModel::mapFromSource(const QModelIndex &sourceIndex) const
{
  return sourceModel()->index(sourceIndex.row() + FIX_ITEMS,
sourceIndex.column());
}

QModelIndex PrefixModel::mapToSource(const QModelIndex &proxyIndex) const
{
  if (!sourceModel())
return QModelIndex();

  return sourceModel()->index(proxyIndex.row() - FIX_ITEMS,
proxyIndex.column());
}

QVariant PrefixModel::data(const QModelIndex &proxyIndex, int role) const
{
  if (proxyIndex.row() < FIX_ITEMS) {
if (role == Qt::DisplayRole)
  return QString("fix item #%1").arg(proxyIndex.row());

return QVariant();
  }
  return QAbstractProxyModel::data(proxyIndex, role);
}

int PrefixModel::rowCount(const QModelIndex &parent) const
{
  if (!sourceModel())
return 0;

  return sourceModel()->rowCount(parent) + FIX_ITEMS;
}

QModelIndex PrefixModel::index(int row, int column, const QModelIndex
&parent) const
{
  return createIndex(row, column, 0);
}

void PrefixModel::setRealModel(RealModel *sourceModel)
{
  if (this->sourceModel() == sourceModel)
return;

  if (this->sourceModel())
this->sourceModel()->disconnect(this);

  QAbstractProxyModel::setSourceModel(sourceModel);
  emit sourceModelChanged();

  connect(sourceModel,
SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this,
SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)));
  connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
  connect(sourceModel,
SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this,
SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
  connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this,
SLOT(sourceRowsRemoved(QModelIndex,int,int)));
  connect(sourceModel, SIGNAL(modelReset()), this, SLOT(sourceReset()));
}

RealModel *PrefixModel::sourceModelInternal() const
{
  return qobject_cast(QAbstractProxyModel::sourceModel());
}

void PrefixModel::sourceRowsInserted(const QModelIndex &, int start, int end)
{
  endInsertRows();
}

void PrefixModel::sourceRowsRemoved(const QModelIndex &, int start, int end)
{
  endRemoveRows();
}

void PrefixModel::sourceRowsAboutToBeInserted(const QModelIndex &, int
start, int end)
{
  beginInsertRows(QModelIndex(), start + FIX_ITEMS, end + FIX_ITEMS);
}

void PrefixModel::sourceRowsAboutToBeRemoved(const QModelIndex &, int
start, int end)
{
  beginRemoveRows(QModelIndex(), start + FIX_ITEMS, end + FIX_ITEMS);
}

void PrefixModel::sourceReset()
{
  beginResetModel();
  endResetModel();
}

Nils
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-17 Thread Peter Kovacs
I dont get it. A project status is a perfect field for a DB.
The query would even group the project in the right way.

select status , projectname
  from todolist
group by statusRank
;

then you could have some code that goes through the objects
print project { arraycontainer.projectname }
If (arraycontainer[i+1].status <> arraycontainer[i].status) { print new_cat() };

sorry for the bad pseudocode but i hope you get the idea.my c++ is not good and 
i want to go to bed.

Peter

> Am 17.04.2015 um 12:24 schrieb François K. :
> 
> Hi Lucien,
> 
> Thanks a lot for your blazingly fast answer :D
> 
>> Can't you simply make the hard-coded entries dynamic too. Just add a
>> column in the db saying that these entries are the hardcoded ones ?
> 
> Sadly, nope, I can't hard-code them in the database because they are entry 
> point to a different view on the same data.
> 
> To make things more clear, I'm building a to-do app. The first screen is a 
> list where the first items are : "Today", "Overdue", "Completed", "Trash", ...
> And then, I want to have the list of "Projects" (which are gathered from the 
> database entries).
> 
> "Today", "Overdue", etc... can't be added as Projects in the database, it 
> makes no sense :(
> 
> 
>> And when doing db stuff, don't forget to use transactions. It can
>> help speeding up stuff a lot.
> 
> Thanks for this advice. I'll do my best to respect this and use transactions 
> everywhere.
> 
> 
> Cheers,
> 
> -- 
> François
> ___
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-17 Thread Lucien Xu
Hi François,

I support this idea:
Why don't you build a model that is built in two step during creation, first, 
build the 6 entries, then build the rest ?

Regards,
Lucien

- Mail original -
> De: "Michael Fuchs" 
> À: "Sailfish OS Developers" 
> Envoyé: Vendredi 17 Avril 2015 12:30:45
> Objet: Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones
> 
> Hi Francois,
> 
> Am 17.04.2015 um 12:24 schrieb François K.:
> > To make things more clear, I'm building a to-do app. The first
> > screen
> > is a list where the first items are : "Today", "Overdue",
> > "Completed", "Trash", ... And then, I want to have the list of
> > "Projects" (which are gathered from the database entries).
> 
> Is'nt it possible to add the items in the QML-part?
> 
> greets, Michael.
> ___
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to
> devel-unsubscr...@lists.sailfishos.org
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-17 Thread Michael Fuchs

Hi Francois,

Am 17.04.2015 um 12:24 schrieb François K.:

To make things more clear, I'm building a to-do app. The first screen
is a list where the first items are : "Today", "Overdue",
"Completed", "Trash", ... And then, I want to have the list of
"Projects" (which are gathered from the database entries).


Is'nt it possible to add the items in the QML-part?

greets, Michael.
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-17 Thread François K .
Hi Lucien,

Thanks a lot for your blazingly fast answer :D

> Can't you simply make the hard-coded entries dynamic too. Just add a
> column in the db saying that these entries are the hardcoded ones ?

Sadly, nope, I can't hard-code them in the database because they are entry 
point to a different view on the same data.

To make things more clear, I'm building a to-do app. The first screen is a list 
where the first items are : "Today", "Overdue", "Completed", "Trash", ...
And then, I want to have the list of "Projects" (which are gathered from the 
database entries).

"Today", "Overdue", etc... can't be added as Projects in the database, it makes 
no sense :(


> And when doing db stuff, don't forget to use transactions. It can
> help speeding up stuff a lot.

Thanks for this advice. I'll do my best to respect this and use transactions 
everywhere.


Cheers,

-- 
François
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Re: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-17 Thread Lucien Xu
Hi François,

Can't you simply make the hard-coded entries dynamic too. Just add a column in 
the db saying that these entries are the hardcoded ones ? With this, you got 
only one query.

And when doing db stuff, don't forget to use transactions. It can help speeding 
up stuff a lot.

Regards,
Lucien

- Mail original -
> De: "François K." 
> À: "Sailfish OS Developers" 
> Envoyé: Vendredi 17 Avril 2015 12:09:20
> Objet: [SailfishDevel] Build a Model with "fixed" items + "dynamic" ones
> 
> Hi !
> 
> Today, my issue is probably more about Qt than SailfishOS, but I'd
> like to try my luck with you first :)
> 
> I want to build a list where the first 6 items are "fixed" (they have
> to always be here) and the following ones are retrieved from a
> database.
> For each of these items, I'd like to also have the numbers of
> contained items (i.e. "My Project : 6 remaining tasks").
> 
> I came with 2 ideas to achieve this :
> 
> 1/ The first one is to build a Model that would inherit from
> QAbstractListModel.
> In the constructor, I would add the first 6 items (hard-code them).
> Then I would add a QSqlQueryModel instance and try to keep things
> up-to-date, thanks to the signals/slots mechanism.
> When updating the model, I would have to query the database 7 times
> (6 times for the hard-coded items, and 1 time for the following
> ones).
> I would also have to be careful when updating the "dynamic" items,
> and do this smartly (remove items that don't exist anymore, add the
> new ones or modifiy the existing ones to avoid too much visual
> glitches, ...)
> It seems a bit convoluted to me, but yeah...
> 
> 2/ The second idea I have is to slightly modify my database scheme
> and build a view with UNION statements. Basically, I would have 7
> SELECT statements UNIONed.
> My Model would then consist in a basic QSqlQueryModel.
> When updating the model, I would have to query the database just one
> time, and everything should update accordingly (magically).
> 
> 
> I don't really know what is the best solution, mostly when it comes
> to performance. What do you guys think ? Any hint, tip or advice to
> achieve my goal ?
> 
> Thanks a lot :)
> 
> --
> François
> ___
> SailfishOS.org Devel mailing list
> To unsubscribe, please send a mail to
> devel-unsubscr...@lists.sailfishos.org
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

[SailfishDevel] Build a Model with "fixed" items + "dynamic" ones

2015-04-17 Thread François K .
Hi !

Today, my issue is probably more about Qt than SailfishOS, but I'd like to try 
my luck with you first :)

I want to build a list where the first 6 items are "fixed" (they have to always 
be here) and the following ones are retrieved from a database.
For each of these items, I'd like to also have the numbers of contained items 
(i.e. "My Project : 6 remaining tasks").

I came with 2 ideas to achieve this :

1/ The first one is to build a Model that would inherit from QAbstractListModel.
In the constructor, I would add the first 6 items (hard-code them).
Then I would add a QSqlQueryModel instance and try to keep things up-to-date, 
thanks to the signals/slots mechanism.
When updating the model, I would have to query the database 7 times (6 times 
for the hard-coded items, and 1 time for the following ones).
I would also have to be careful when updating the "dynamic" items, and do this 
smartly (remove items that don't exist anymore, add the new ones or modifiy the 
existing ones to avoid too much visual glitches, ...)
It seems a bit convoluted to me, but yeah...

2/ The second idea I have is to slightly modify my database scheme and build a 
view with UNION statements. Basically, I would have 7 SELECT statements UNIONed.
My Model would then consist in a basic QSqlQueryModel.
When updating the model, I would have to query the database just one time, and 
everything should update accordingly (magically).


I don't really know what is the best solution, mostly when it comes to 
performance. What do you guys think ? Any hint, tip or advice to achieve my 
goal ?

Thanks a lot :)

-- 
François
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org