7 #include "CurveNameListEntry.h"
8 #include "CurveNameList.h"
9 #include "DocumentSerialize.h"
10 #include "EngaugeAssert.h"
12 #include "QtToString.h"
14 #include <QXmlStreamWriter>
16 const QString PIPE (
"|");
17 const QString SPACE (
" ");
18 const QString TAB (
"\t");
31 LOG4CPP_INFO_S ((*mainCat)) <<
"CurveNameList::containsCurveNameCurrent"
32 <<
" entryCount=" << m_modelCurvesEntries.count();
35 QStringList::const_iterator itr;
36 for (itr = m_modelCurvesEntries.begin (); itr != m_modelCurvesEntries.end (); itr++) {
48 bool CurveNameList::curveNameIsAcceptable (
const QString &curveNameNew,
52 bool success = (!curveNameNew.isEmpty ());
57 for (
int row1 = 0; row1 < m_modelCurvesEntries.count(); row1++) {
61 QString curveNameCurrent1 = (row1 == row ?
63 curvesEntry1.curveNameCurrent());
65 for (
int row2 = row1 + 1; row2 < m_modelCurvesEntries.count(); row2++) {
69 QString curveNameCurrent2 = (row2 == row ?
71 curvesEntry2.curveNameCurrent());
73 if (curveNameCurrent1 == curveNameCurrent2) {
89 LOG4CPP_DEBUG_S ((*mainCat)) <<
"CurveNameList::data"
90 <<
" isRoot=" << (index.isValid () ?
"no" :
"yes")
91 <<
" role=" << roleAsString (role).toLatin1 ().data ();
93 if (!index.isValid ()) {
98 int row = index.row ();
99 if (row < 0 || row >= m_modelCurvesEntries.count ()) {
103 if ((role != Qt::DisplayRole) &&
104 (role != Qt::EditRole)) {
110 if (index.column () == 0) {
112 }
else if (index.column () == 1) {
113 return curvesEntry.curveNameOriginal();
114 }
else if (index.column () == 2) {
115 return curvesEntry.numPoints ();
117 ENGAUGE_ASSERT (
false);
118 return curvesEntry.curveNameOriginal();
125 if (index.isValid ()) {
129 return QAbstractTableModel::flags (index) |
130 Qt::ItemIsDragEnabled |
132 Qt::ItemIsSelectable |
138 return QAbstractTableModel::flags (index) |
139 Qt::ItemIsDropEnabled;
144 QModelIndex CurveNameList::indexForValue (
const QModelIndex &indexToSkip,
145 const QVariant &value)
const
147 LOG4CPP_INFO_S ((*mainCat)) <<
"CurveNameList::indexForValue";
149 for (
int row = 0; row <
rowCount(); row++) {
151 QModelIndex indexSearch = index (row, 0);
153 if (indexToSkip != indexSearch) {
155 if (
data (indexSearch) == value) {
169 const QModelIndex &parent)
171 bool skip = (count != 1 || row < 0 || row >
rowCount () || parent.isValid());
173 LOG4CPP_INFO_S ((*mainCat)) <<
"CurveNameList::insertRows"
175 <<
" count=" << count
176 <<
" parentRow=" << parent.row()
177 <<
" parentCol=" << parent.column()
178 <<
" isRoot=" << (parent.isValid () ?
"no" :
"yes")
179 <<
" skip=" << (skip ?
"yes" :
"no");
191 QString before = m_modelCurvesEntries.join (PIPE).replace (TAB, SPACE);
193 beginInsertRows (QModelIndex (),
199 m_modelCurvesEntries.insert (row,
204 QString after = m_modelCurvesEntries.join (PIPE).replace (TAB, SPACE);
206 LOG4CPP_INFO_S ((*mainCat)) <<
"CurveNameList::insertRows"
207 <<
" before=" << before.toLatin1().data()
208 <<
" after=" << after.toLatin1().data();
215 const QModelIndex &parent)
217 bool skip = (count != 1 || row < 0 || row >
rowCount () || parent.isValid());
219 LOG4CPP_DEBUG_S ((*mainCat)) <<
"CurveNameList::removeRows"
221 <<
" count=" << count
222 <<
" isRoot=" << (parent.isValid () ?
"no" :
"yes")
223 <<
" skip=" << (skip ?
"yes" :
"no");
225 bool success =
false;
227 beginRemoveRows (QModelIndex (),
231 m_modelCurvesEntries.removeAt (row);
240 int count = m_modelCurvesEntries.count ();
242 LOG4CPP_DEBUG_S ((*mainCat)) <<
"CurveNameList::rowCount count=" << count;
247 bool CurveNameList::rowIsUnpopulated (
int row)
const
253 QString fields = m_modelCurvesEntries.at (row);
255 return entryAtRow.entryHasNotBeenPopulated ();
259 const QVariant &value,
262 LOG4CPP_INFO_S ((*mainCat)) <<
"CurveNameList::setData"
263 <<
" indexRow=" << index.row ()
264 <<
" indexCol=" << index.column ()
265 <<
" indexValid=" << (index.isValid() ?
"valid" :
"invalid")
266 <<
" valueValid=" << (value.isValid () ?
"valid" :
"invalid")
267 <<
" value=" << value.toString().toLatin1().data()
268 <<
" role=" << roleAsString (role).toLatin1 ().data ();
270 bool success =
false;
272 if (index.isValid()) {
275 int row = index.row ();
276 if (row < m_modelCurvesEntries.count ()) {
281 QString before = m_modelCurvesEntries.join (PIPE).replace (TAB, SPACE);
283 if (!value.isValid () && (role == Qt::EditRole)) {
286 m_modelCurvesEntries.removeAt (row);
293 if (index.column () == 0) {
295 if (role == Qt::EditRole) {
298 if (curveNameIsAcceptable (value.toString (),
302 m_modelCurvesEntries [row] = curvesEntry.
toString ();
309 }
else if ((role == Qt::DisplayRole) ||
310 (curveNameIsAcceptable (value.toString(),
317 if (rowIsUnpopulated (row)) {
321 m_modelCurvesEntries [row] = curvesEntry.
toString ();
322 tryToRemoveOriginalCopy (index,
329 }
else if (index.column () == 1) {
331 m_modelCurvesEntries [row] = curvesEntry.
toString ();
332 }
else if (index.column () == 2) {
334 m_modelCurvesEntries [row] = curvesEntry.
toString ();
336 ENGAUGE_ASSERT (
false);
340 emit dataChanged (index,
344 QString after = m_modelCurvesEntries.join (PIPE).replace (TAB, SPACE);
346 LOG4CPP_INFO_S ((*mainCat)) <<
"CurveNameList::setData setting"
347 <<
" before=" << before.toLatin1().data()
348 <<
" after=" << after.toLatin1().data();
359 return Qt::MoveAction;
362 void CurveNameList::tryToRemoveOriginalCopy (
const QModelIndex &index,
363 const QVariant &value,
367 if (index.column () == 0 && role == Qt::DisplayRole) {
368 QModelIndex indexToRemove = indexForValue (index,
370 if (indexToRemove.isValid()) {
372 QString before = m_modelCurvesEntries.join (PIPE).replace (TAB, SPACE);
374 beginRemoveRows (QModelIndex (),
376 indexToRemove.row());
377 m_modelCurvesEntries.removeAt (indexToRemove.row ());
380 emit dataChanged (indexToRemove,
383 QString after = m_modelCurvesEntries.join (PIPE).replace (TAB, SPACE);
385 LOG4CPP_INFO_S ((*mainCat)) <<
"CurveNameList::setData removed"
386 <<
" indexRow=" << indexToRemove.row ()
387 <<
" indexCol=" << indexToRemove.column ()
388 <<
" before=" << before.toLatin1().data()
389 <<
" after=" << after.toLatin1().data();
bool containsCurveNameCurrent(const QString &curveName) const
Return true if specified curve name is already in the list.
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
Insert one row.
Utility class for converting the QVariant in CurveNameList to/from the curve names as QStrings...
virtual Qt::DropActions supportedDropActions() const
Allow dragging for reordering.
void setCurveNameCurrent(const QString &curveNameCurrent)
Set method for current curve name.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Override normal flags with additional editing flags.
QString toString() const
QString for creating QVariant.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Store one curve name data.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Retrieve data from model.
virtual bool removeRows(int row, int count, const QModelIndex &parent)
Remove one row.
void setCurveNameOriginal(const QString &curveNameOriginal)
Set method for original curve name.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
One row per curve name.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Columns are current curve name in first column, and original curve name in second column...
QString curveNameCurrent() const
Curve name displayed in DlgSettingsCurveAddRemove.
CurveNameList()
Default constructor.
void setNumPoints(int numPoints)
Set method for point count.