Results 1 to 5 of 5

Thread: Change in color map?

  1. #1
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Change in color map?

    I upgraded to the latest trunk version of Qwt, and one change in particular caused me some grief, but maybe there is a better way of doing things now?

    I used to pass in a pointer to a colormap which I controlled. Basically, I could change the min/max values of the colorbar, log or not, etc. interactively from my GUI and since I was passing a pointer into the QwtPlotSpectrogram, the user could see the changes on the fly.

    Now, Qwt wants to take ownership of the color map and I lost my control over the colors, etc. after I set the colormap.

    I hope this all makes sense.

    Is there a better way of doing this?

    Thanks,
    Joey

  2. #2
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change in color map?

    One other problem: I think the copy constructors for QwtLinearColorMap/QwtAlphaColorMap are wrong.

    d_data = new PrivateData;
    *this = other;

    The *this=other will overwrite the new d_data!

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change in color map?

    Quote Originally Posted by bigjoeystud View Post
    Now, Qwt wants to take ownership of the color map and I lost my control over the colors, etc. after I set the colormap.
    These clone/copy methods of Qwt 5.x were a major source for user problems. That's why I have removed most of them and pass pointers instead - like everyone is used to from the Qt API. But why is this a problem if you want to manipulate the color map from application code ?

    Uwe

    PS: Right now I'm working to improve the accurancy of the raster item class and to introduce an additional type of raster data for values stored in a matrix. So don't be surpised to find undocumented APIs and ongoing changes.

  4. #4
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change in color map?

    Quote Originally Posted by Uwe View Post
    These clone/copy methods of Qwt 5.x were a major source for user problems. That's why I have removed most of them and pass pointers instead - like everyone is used to from the Qt API. But why is this a problem if you want to manipulate the color map from application code ?
    I have a class which is defined like so:

    class ImageData: public QObject, public QwtRasterData
    {
    ...
    private:

    // We store pointers to a value to use for the color bar
    // We need this instead of member variable so that the interactive color bar works

    double *_colorMin;
    double *_colorMax;
    FuncPtr *_colorBarModifier;
    };

    My GUI changes the values of those pointers.

    QwtPlotSpectrogram *spectrogram = new QwtPlotSpectrogram ();
    spectrogram->setColorMap (new TransparentLinearColorMap (_colorMap));
    spectrogram->setData (image);

    image is of type ImageData which is derived from QwtRasterData. _colorMap was connected to the same values of the the min/max. Thus, when the GUI is up and the user is interacting with the color bar and Qwt replots; it is using the current value of those pointers.

    Why this no longer works is I have to do this:
    spectrogram->setColorMap (new TransparentLinearColorMap (_colorMap));
    instead of my previous "spectrogram->setColorMap (_colorMap);" which would make the spectrogram use the same colorMap that the interactive GUI was using. In other words, since spectrogram owns the new'ed colorMap, my GUI is no longer interacting with the right one.

    I hope that all makes sense! Anyway, I'm not saying this is the best way of doing this, but maybe I'm missing something easy on either fixing this or a better design?

    Quote Originally Posted by Uwe View Post
    PS: Right now I'm working to improve the accurancy of the raster item class and to introduce an additional type of raster data for values stored in a matrix. So don't be surpised to find undocumented APIs and ongoing changes.
    I look forward to this! Especially if we can have multi-dimensional matrices and easy ways of slicing them.

    Joey

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change in color map?

    Quote Originally Posted by bigjoeystud View Post
    Why this no longer works is I have to do this:
    spectrogram->setColorMap (new TransparentLinearColorMap (_colorMap));
    instead of my previous "spectrogram->setColorMap (_colorMap);" which would make the spectrogram use the same colorMap that the interactive GUI was using. In other words, since spectrogram owns the new'ed colorMap, my GUI is no longer interacting with the right one.
    What about changing your code, so that _colorMap becomes a pointer allocated by new. Then there will be no copy ( in the meantime I have disabled the copy constructor ! ) and you can maniuplate the one and only color map from application code. Note that you have to reassign the color map after changes to disable the internal image cache and trigger the optional auto replot ( of course you can do this manually as well ).

    All you have to take care of is, that the color map will be deleted by the destructor of the spectrogram. So it might be better to use the getter of the spectrogram object instead of an additional pointer.

    ... multi-dimensional matrices and easy ways of slicing them.
    In the meantime I have checked in a first version of this class. The new rasterview example shows how to use it. The implementation is not complete, not tested for printing and there are still some 1 pixel alignment errors left. Also the documentation is not yet done, but you can check the code of the rasterview example to see if this would be something for your situation.

    Comments are welcome,
    Uwe

Similar Threads

  1. Change the color of QRubberBand
    By franco.amato in forum Qt Programming
    Replies: 14
    Last Post: 4th August 2011, 16:30
  2. Replies: 3
    Last Post: 22nd January 2010, 16:46
  3. how to change the color of the frame
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 12th May 2009, 12:46
  4. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25
  5. Change HLine color
    By smtgra011 in forum Newbie
    Replies: 3
    Last Post: 5th July 2007, 06:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.