16#include <QXmlStreamWriter>
33 CurrentCurveToOriginalCurve::const_iterator itr;
34 for (itr = m_currentCurveToOriginalCurve.begin (); itr != m_currentCurveToOriginalCurve.end (); ++itr) {
36 if (itr.key () == curveName) {
49 QTextStream str (&out);
51 for (
int row = 0; row <
rowCount (); row++) {
54 QString curveOriginal;
55 unsigned int points = 0;
56 if (m_currentCurveToOriginalCurve.contains (curveCurrent)) {
57 curveOriginal = m_currentCurveToOriginalCurve [curveCurrent];
58 if (m_originalCurveToPointCount.contains (curveOriginal)) {
60 points = m_originalCurveToPointCount [curveOriginal];
64 str <<
"\n current=" << curveCurrent.toLatin1().data()
65 <<
" original=" << curveOriginal
66 <<
" points=" << points;
74 return m_currentCurveToOriginalCurve [currentCurve];
79 QString originalCurve = m_currentCurveToOriginalCurve [currentCurve];
81 return m_originalCurveToPointCount [originalCurve];
84bool CurveNameList::curveNameIsAcceptable (
const QString &curveNameNew,
88 bool success = (!curveNameNew.isEmpty ());
93 for (
int row1 = 0; row1 <
rowCount(); row1++) {
97 QString curveNameCurrent1 = (row1 == row ?
99 data (index1).toString ());
101 for (
int row2 = row1 + 1; row2 <
rowCount(); row2++) {
105 QString curveNameCurrent2 = (row2 == row ?
107 data (index2).toString ());
109 if (curveNameCurrent1 == curveNameCurrent2) {
124 if (index.isValid ()) {
128 return (QStandardItemModel::flags (index) |
129 Qt::ItemIsDragEnabled |
131 Qt::ItemIsSelectable |
132 Qt::ItemIsEditable) & ~Qt::ItemIsDropEnabled;
137 return QStandardItemModel::flags (index) |
138 Qt::ItemIsDropEnabled;
144 const QString &curveCurrent,
145 const QString &curveOriginal,
146 unsigned int pointCount)
150 <<
" curveCurrent=" << curveCurrent.toLatin1().data()
151 <<
" curveOriginal=" << curveOriginal.toLatin1().data()
152 <<
" points=" << pointCount;
154 QStandardItem *
item =
new QStandardItem (curveCurrent);
155 QStandardItemModel::insertRow (row,
item);
158 beginInsertRows (QModelIndex (),
162 m_currentCurveToOriginalCurve [curveCurrent] = curveOriginal;
163 m_originalCurveToPointCount [curveOriginal] = pointCount;
175 return QStandardItemModel::item (row, column);
181 for (
int i = 0; i < rowsSelected.count(); i++) {
182 int row = signed (rowsSelected [i]);
185 QString currentCurve = data (idx).toString ();
186 if (m_currentCurveToOriginalCurve.contains (currentCurve)) {
188 QString originalCurve = m_currentCurveToOriginalCurve [currentCurve];
189 if (m_originalCurveToPointCount.contains (originalCurve)) {
191 numPoints += m_originalCurveToPointCount [originalCurve];
196 return unsigned (numPoints);
201 const QModelIndex &parent)
205 bool skip = (count != 1 || row < 0 || row >
rowCount () || parent.isValid());
207 QString before, after;
214 beginRemoveRows (QModelIndex (),
219 for (
int rowRemove = row; rowRemove < row + count; rowRemove++) {
220 QStandardItemModel::removeRows (row,
232 <<
" count=" << count
233 <<
" isRoot=" << (parent.isValid () ?
"no" :
"yes")
234 <<
" skip=" << (skip ?
"yes" :
"no")
235 <<
" before=" << before.toLatin1().data()
236 <<
" after=" << after.toLatin1().data();
245 m_currentCurveToOriginalCurve.clear();
246 m_originalCurveToPointCount.clear();
251 int count = QStandardItemModel::rowCount ();
260 const QVariant &value,
264 <<
" row=" << index.row()
265 <<
" value=" << value.toString().toLatin1().data()
269 if (role == Qt::EditRole) {
272 if (curveNameIsAcceptable (value.toString(),
279 QString curveCurrentOld = data (idxOld).toString ();
280 QString curveCurrentNew = value.toString ();
283 QString curveOriginal;
284 if (m_currentCurveToOriginalCurve.contains (curveCurrentOld)) {
287 curveOriginal = m_currentCurveToOriginalCurve [curveCurrentOld];
290 m_currentCurveToOriginalCurve.remove (curveCurrentOld);
293 m_currentCurveToOriginalCurve [curveCurrentNew] = curveOriginal;
296 success = QStandardItemModel::setData (index,
308 success = QStandardItemModel::setData (index,
326 QStandardItemModel::setItem (row,
334 <<
" before=" << before.toLatin1().data()
335 <<
" after=" << after.toLatin1().data();
340 return Qt::MoveAction;
@ NUMBER_CURVE_NAME_LIST_COLUMNS
@ CURVE_NAME_LIST_COLUMN_CURRENT
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
QString roleAsString(int role)
void reset()
Clear all information.
bool containsCurveNameCurrent(const QString &curveName) const
Return true if specified curve name is already in the list.
virtual int columnCount(const QModelIndex &parent) const
One column.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
One row per curve name.
unsigned int currentCurveToPointCount(const QString ¤tCurve) const
Return the point count for the specified current curve.
QString currentCurvesAsString() const
For debugging we dump the curve names.
unsigned int numPointsForSelectedCurves(const QList< unsigned int > &rowsSelected) const
Return the number of points associated with the selected curves, as specified by their row numbers.
virtual QStandardItem * item(int row, int column=0) const
Retrieve data from model.
virtual void setItem(int row, int column, QStandardItem *item)
Store one curve name data.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Override normal flags with additional editing flags.
virtual bool removeRows(int row, int count, const QModelIndex &parent)
Remove one row.
void insertRow(int row, const QString &curveCurrent, const QString &curveOriginal, unsigned int pointCount)
Create a new entry at the specified row.
CurveNameList()
Default constructor.
QString currentCurveToOriginalCurve(const QString ¤tCurve) const
Return the original curve for the specified current curve.
virtual Qt::DropActions supportedDropActions() const
Allow dragging for reordering.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
Store data for one curve name.
#define LOG4CPP_INFO_S(logger)
#define LOG4CPP_DEBUG_S(logger)