Hello community!
I have following situation:
typedef QMapIterator<double, QCPFinancialData> QCPFinancialDataMapIterator;
class QCP_LIB_DECL QCPFinancialData
{
public:
QCPFinancialData();
QCPFinancialData(double key, double open, double high, double low, double close);
double key, open, high, low, close;
friend QDebug operator<<(QDebug dbg, QCPFinancialData& data); // AW
};
typedef QMapIterator<double, QCPFinancialData> QCPFinancialDataMapIterator;
class QCP_LIB_DECL QCPFinancialData
{
public:
QCPFinancialData();
QCPFinancialData(double key, double open, double high, double low, double close);
double key, open, high, low, close;
friend QDebug operator<<(QDebug dbg, QCPFinancialData& data); // AW
};
To copy to clipboard, switch view to plain text mode
Here the code snippet:
QCPFinancialDataMap map;
QCPFinancialDataMapIterator it( map );
// initialize map ...
// map after initialization:
map
= QCPFinancialDataMap
(QMap(0,QCPFinancialData
(0,
10,
15,
8,
12) ) QMap(900,QCPFinancialData
(900,
11,
16,
7,
13) ) QMap(1800,QCPFinancialData
(1800,
12,
17,
6,
14) ) QMap(2700,QCPFinancialData
(2700,
13,
18,
5,
15) ) ). . .
QCPFinancialDataMap map;
QCPFinancialDataMapIterator it( map );
// initialize map ...
// map after initialization:
map = QCPFinancialDataMap(QMap(0,QCPFinancialData(0,10,15,8,12) ) QMap(900,QCPFinancialData(900,11,16,7,13) ) QMap(1800,QCPFinancialData(1800,12,17,6,14) ) QMap(2700,QCPFinancialData(2700,13,18,5,15) ) )
. . .
To copy to clipboard, switch view to plain text mode
// I make 3 calls to it.next(), all behaving as expected.
Then I have to go one step backwards, so I call it.previous(), but without any effect! I have to make a second call to it.previous() to get the desired result! Same behavior moving the iterator forward to reach the original position! - see code snippet and printout -
qDebug() << "1: it.value().close =" << it.value().close; // OK, is 14
it.previous(); // no effect!
qDebug() << "2: it.value().close =" << it.value().close; // should be 13!
it.previous(); // works as expected. Why is a double call of previous() necessary?
qDebug() << "3: it.value().close =" << it.value().close; // OK, is 13
currentBinData.close = it.value().close;
it.next(); // no effect!
qDebug() << "4: it.value().close =" << it.value().close; // should be 14!
it.next(); // works as expected. Why is a double call of next() necessary?
qDebug() << "5: it.value().close =" << it.value().close; // OK, is 14
qDebug() << "1: it.value().close =" << it.value().close; // OK, is 14
it.previous(); // no effect!
qDebug() << "2: it.value().close =" << it.value().close; // should be 13!
it.previous(); // works as expected. Why is a double call of previous() necessary?
qDebug() << "3: it.value().close =" << it.value().close; // OK, is 13
currentBinData.close = it.value().close;
it.next(); // no effect!
qDebug() << "4: it.value().close =" << it.value().close; // should be 14!
it.next(); // works as expected. Why is a double call of next() necessary?
qDebug() << "5: it.value().close =" << it.value().close; // OK, is 14
To copy to clipboard, switch view to plain text mode
print out:
1: it.value().close = 14
2: it.value().close = 14
3: it.value().close = 13
4: it.value().close = 13
5: it.value().close = 14
The code is doing what I want, but it is not clean.
Any idea?
Thank you for your time.
Alain
Bookmarks