Hi Uwe,
I posted this on the mailing group, but thought I should have a go here too. Actually which method do you prefer? Mailing list or this forum?
Anyway...
I'm in the process of updating my code to Qwt 6.0.0. However, with most of the copy constructors gone it is making life very difficult. For example, previously I used to do this for a linear colour map:
... some code to edit the linear colour map by setting new colour stops. Then,
SomeClass::editColourMap( QwtLinearColorMap* colourMap) {
... some code to edit the linear colour map by setting new colour stops. Then,
scaleWidget_->setColorMap( QwtDoubleInterval( 0.0, 1.0), *colourMap->copy()); }
To copy to clipboard, switch view to plain text mode
While I can do this is the new version:
scaleWidget_->setColorMap( QwtInterval( 0.0, 1.0), colourMap);
scaleWidget_->setColorMap( QwtInterval( 0.0, 1.0), colourMap);
To copy to clipboard, switch view to plain text mode
The original variable "colourMap" may not be persistant ... So I need to make a copy first. However, I can't do this:
scaleWidget_
->setColorMap
( QwtInterval
( 0.0,
1.0),
new QwtLinearColorMap( colourMap
));
scaleWidget_->setColorMap( QwtInterval( 0.0, 1.0), new QwtLinearColorMap( colourMap));
To copy to clipboard, switch view to plain text mode
because there is private data within the class that is accessed via a pointer. The only thing I can think of to do is something like this:
QVector<double> colourStops = origColourMap->colorStops();
for ( int i = 1; i < colourStop.size() - 1; ++i) {
copyMap->addColorStop( colourStop(i), blah_colour_from_rgb_lookup); // You get the idea.
}
scaleWidget_->setColorMap( QwtInterval( 0.0, 1.0), copyMap);
QwtLinearColorMap* copyMap = new QwtLinearColorMap( origColourMap.color1(), origColourMap.color2());
QVector<double> colourStops = origColourMap->colorStops();
for ( int i = 1; i < colourStop.size() - 1; ++i) {
copyMap->addColorStop( colourStop(i), blah_colour_from_rgb_lookup); // You get the idea.
}
scaleWidget_->setColorMap( QwtInterval( 0.0, 1.0), copyMap);
To copy to clipboard, switch view to plain text mode
Any suggestions on this? How do I copy a colour map?
Have Fun !!
Shane
Added after 21 minutes:
Hi Uwe,
Just looking at the QwtLinearColorMap and QwtColorMap classes more closely and I'm note sure why you have gone for using a pointer to the class "PrivateData". All the members of PrivateData are well behaved in that none of the variables require the use of a user defined copy constructor to copy the data. The default C++ copy constructor will work fine. However, because QwtLinearColorMap uses a pointer to this data, you would need to have a user defined copy constructor. For eample is you have a class:
class A {
public:
A() {
myString = new char[16];
strcpy( myString, "Hello There");
};
~A() {
delete myString;
}
private:
char *myString;
}
class A {
public:
A() {
myString = new char[16];
strcpy( myString, "Hello There");
};
~A() {
delete myString;
}
private:
char *myString;
}
To copy to clipboard, switch view to plain text mode
then to make a copy of class A you would need to create a user defined copy constructor to copy the contents of myString to the new copy. However, if you were to do this:
class B {
public:
B( const Qstring &aString) {
myString = aString;
};
~B() {
}
private:
}
class B {
public:
B( const Qstring &aString) {
myString = aString;
};
~B() {
}
private:
QString myString;
}
To copy to clipboard, switch view to plain text mode
Then you don't need to user defined copy constructor or to clean up any data in a destructor. Then the following would then be valid:
B b1( "Hello There"), b2;
B b3( b1);
b2 = b1;
// b2 and b3 are now copies of b1.
B b1( "Hello There"), b2;
B b3( b1);
b2 = b1;
// b2 and b3 are now copies of b1.
To copy to clipboard, switch view to plain text mode
The same is true of any complex classes like std::vector, std::valarray, QVector, QString, etc.
Bookmarks