jdataview API

Luigi Castelli's icon

Hi there,

I am experimenting with the jdataview.h API and I find it very powerful and flexible yet very under-documented.
After carefully studying the dbviewer SDK example and all the info I could find on the jdataview.h files I managed to compile an external with the dataview stuff but without the use of a database.
I can now insert columns and rows with numeric data, and change the data values by dragging or by inline editing. Pretty cool.
However, this was not really an easy task due to the lack of API documentation and the fact that a lot of the functions prototyped in jdataview.h are not exported.

At this point, I still have a million of questions, but I would like to start with just a few…

1 - I would like to implement a custom column/cell painting method.
I see there are some function prototypes that indicate this could be possible but I need some guidance as far as how to go about it.
Specifically I would like to draw a bar indicator in every cell.
I see there's a jcolumn_setcustompaint() function, however I am not sure if that's the way to go, since I don't really want to have to draw the whole column, but only a single cell.

2 - I also see that when clicking on the column header I can access a column sorting feature.
Unfortunately all columns are sorted at the same time and I cannot even understand what the sorting criterias are. What I would like to implement is a way to sort the columns independently from each other and be in control of the sorting criterias, which might change depending on the data types displayed. I see it's possible to implement a custom sorting method probably using the jcolumn_setcustomsort() function [ what about jcolumn_setoverridesort() ??? ] Could someone provide some guidance on how exactly?

3 - I am thinking I need a way of getting notified when I hover, click or drag with the mouse on a per-cell basis.
This is because I would like to implement a behavior where a single column, row or cell might be selected.
Very similar to the Selection Mode of jit.cellblock. How would I go about it?

4 - Last but not least, (and this could be just me being a little paranoic) I am noticing that in my code I am writing a lot of custom attribute accessor functions. Many of the custom accessors refer to an attribute of the t_jdataview struct in a somewhat redundant way. I am wondering if I have overlooked something that might help me slim down my code.

For example:

typedef struct _myobject
{
    t_jbox   box;
    t_object *dataview;
} t_myobject;

//--------------

CLASS_ATTR_RGBA(c,         "rowcolor1",    ATTR_FLAGS_NONE, t_myobject, dataview);
CLASS_ATTR_ACCESSORS(c,         "rowcolor1",    (method)dataview_rowcolor1_get, (method)dataview_rowcolor1_set);
CLASS_ATTR_DEFAULT_SAVE_PAINT(c, "rowcolor1",    ATTR_FLAGS_NONE, "1.0 1.0 1.0 1.0");

Here I am not even holding the rowcolor1 attribute in my object data structure, but I am referencing the d_rowcolor1 field of the t_jdataview struct.
Of course I need custom setter and getter functions which more or less act as wrappers for jdataview_getrowcolor1() and jdataview_setrowcolor1(). So in my code I am basically creating an attribute to reference another attribute. Is there a way to use the t_jdataview d_rowcolor1 attribute directly, without the need of implementing a custom setter and getter ?

I think that's all for now...

Apologies for the lengthy post and a million thanks to who could provide some enlightment.

- Luigi

Joshua Kit Clayton's icon

Hi Luigi,

Some quick answers to your questions. In many ways, you are going to be on your own with this API. It is not a priority to document or support this API for third party developers at this time. You are welcome to use at your own risk, however.

1. We are not supporting any custom cellpainting. We used to use it in cellblock, and cellblock was re-written not to use jdataview because there were too many issues with it.

2. We do not support different columns to be supported independently. One column *always* sorts an entire row (just like iTunes or similar), either numerically or by alphabetical ordering.

3. You can poll the mouse position with the following function and translate to your view coordinates. It will be up to you to filter this and take any desired action. Here's how mousestate does it:

void mousestate_getmouse(t_mousestate *x, Point* where)
{
    int sx, sy;
    t_object *view = NULL;
    double cx, cy; 

    jmouse_getposition_global(&sx, &sy);
    if (x->m_mode == MS_MODE_LOCAL) {
        view = jpatcher_get_firstview(x->m_patcher);
    }
    else if (x->m_mode == MS_MODE_FRONTPATCHER) {
        view = jwind_getactive();
    }
    if (view) {
        // view might be a jwind or a patcherview
        // it doesn't matter as long as it implements screentocanvas.
        object_method(view, gensym("screentocanvas"), sx, sy, &cx, &cy);
    }
    else {
        cx = sx;
        cy = sy;
    }
    where->h = (short) cx;
    where->v = (short) cy;
}

4. There are no other attribute shortcuts I can think of at this time.

Sorry if this isn't exactly the response you were looking for, but there are no plans to support this API any further than the header and the example SDK project. Good luck, and have fun.

-Joshua

Luigi Castelli's icon

Ok Joshua, I understand...
Thanks for taking the time to answer.

Best

- Luigi