KCategoryView modification proposal

lbell at tsc4.com lbell at tsc4.com
Tue Jul 31 22:24:58 BST 2007


>> So this kind of technical conversation, has to be private or public?
>> If you prefer to have it public (but it will generate a lot of traffic, I
>> think) feel free to post our mails to kfm developer mailing list

>Yeah, from my point of view this conversation should be public. As always,
>the more eyes looking, the less errors committed by design, better code.

>Bye,
>Rafael Fernández López.

So I post in list


I want to discuss about how to improve KCategoryView including the
possibility of reusing it in others projects.
The target can be Kde 4.1 or 4.2 is not a problem, if we can build a
powerful feature.

First we need data structure to take into account categories, only so we can
have a reusable view. This means that we have to create a model for data.
The problem is to have a very fast structure. Please, take into account
that using a c++ object for items and categories can be make fast by using
a custom allocator, that is a new operator that use a pool (if we ever
need it).

We need that, so we can not only reuse this view in others projects, that
have different requirements from Dolphin, but we can use it in others
Dolphin views (as the column one). It will be a valuable addition for kde.

So I propose to have this structure :
We have categories containers that owns the items.
Each container has a state (closed/open), a bounding rectangle for the
gadgetry and a total space rectangle taking into account the contained items.

Each item has a pointer to the real item, a bound rectangle relative to the
parent, a sequence index and a backpointer to the parent.
With these information we are able to open end close categories in a
hurry, because the calculations are done in the resize/populate phase
only.
The calculation of positions are done at the category first (bounding
rect), then at item. Taking advantage from the fact that the categories
are much  less numerous than items, we can put some others optimizations.
For example, when we are looking for the mouse click position we can do a
binary search in the categories array, then in the selected category
items.
If the category is closed, we can use its real size by ignoring items.

The code is not yet compiling, but I have few time to finish it and, if
someone agree on this analysis, we can develop it together. In adjoint I
have little qt experience.


I report the data structures as a sample:
// Gli item
class KCategoryItem {
    QModelIndex itemIndex;
    QRect       bounds;
    int         sequenceIndex; // sequence
    KCategoryContainer *parent;
    public:
    KCategoryItem(KCategoryContainer *theParent, const QModelIndex index,
const int sequence)
    {
        parent          = theParent ;
        itemIndex       = index ;
        sequenceIndex   = sequence ;
    }
    ~KCategoryItem()
    {
    }

};

class KCategoryContainer {
	QString	Name;
	QRect	TotalBounds; // including childrens
	QRect	ActualBounds;	// if closed or open
	QBool	isClosed;		// Or Open
	QVector<KCategoryItem> items;
public:

    KCategoryContainer(const QString & theName): isClosed(false)
    {
        Name = theName ;
        items = new QVector<KCategoryItem>();
    }

    ~KCategoryContainer()
    {
        items->clear();
    }

    void insertIndex(const QModelIndex index)
    {
        KCategoryItem *pNewInsert = new KCategoryItem(index, items.size() );
        items.append(pNewInsertzs);
    }
    void CalculateSize();
    int itemCounts() const
    {
        return item.size();
    }
};

bye

Luca Bellonda







More information about the kfm-devel mailing list