Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
CurveNameList Class Reference

Model for DlgSettingsCurveList and CmdSettingsCurveList. More...

#include <CurveNameList.h>

Inheritance diagram for CurveNameList:
Inheritance graph
Collaboration diagram for CurveNameList:
Collaboration graph

Public Member Functions

 CurveNameList ()
 Default constructor.
 
virtual int columnCount (const QModelIndex &parent) const
 One column.
 
bool containsCurveNameCurrent (const QString &curveName) const
 Return true if specified curve name is already in the list.
 
QString currentCurvesAsString () const
 For debugging we dump the curve names.
 
QString currentCurveToOriginalCurve (const QString &currentCurve) const
 Return the original curve for the specified current curve.
 
unsigned int currentCurveToPointCount (const QString &currentCurve) const
 Return the point count for the specified current curve.
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 Override normal flags with additional editing flags.
 
void insertRow (int row, const QString &curveCurrent, const QString &curveOriginal, unsigned int pointCount)
 Create a new entry at the specified row.
 
virtual QStandardItemitem (int row, int column=0) const
 Retrieve data from model.
 
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 bool removeRows (int row, int count, const QModelIndex &parent)
 Remove one row.
 
void reset ()
 Clear all information.
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 One row per curve name.
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role)
 Store data for one curve name.
 
virtual void setItem (int row, int column, QStandardItem *item)
 Store one curve name data.
 
virtual Qt::DropActions supportedDropActions () const
 Allow dragging for reordering.
 

Detailed Description

Model for DlgSettingsCurveList and CmdSettingsCurveList.

This is displayed as a QListView, with visible first column showing current curve name. Second column is hidden with curve name at the start of editing, or empty if none.

Definition at line 27 of file CurveNameList.h.

Constructor & Destructor Documentation

◆ CurveNameList()

CurveNameList::CurveNameList ( )

Default constructor.

Definition at line 18 of file CurveNameList.cpp.

18 :
19 QStandardItemModel()
20{
21}

Member Function Documentation

◆ columnCount()

int CurveNameList::columnCount ( const QModelIndex & parent) const
virtual

One column.

Definition at line 23 of file CurveNameList.cpp.

24{
26}
@ NUMBER_CURVE_NAME_LIST_COLUMNS

◆ containsCurveNameCurrent()

bool CurveNameList::containsCurveNameCurrent ( const QString & curveName) const

Return true if specified curve name is already in the list.

Definition at line 28 of file CurveNameList.cpp.

29{
30 LOG4CPP_INFO_S ((*mainCat)) << "CurveNameList::containsCurveNameCurrent";
31
32 // Search for curve with matching name
33 CurrentCurveToOriginalCurve::const_iterator itr;
34 for (itr = m_currentCurveToOriginalCurve.begin (); itr != m_currentCurveToOriginalCurve.end (); ++itr) {
35
36 if (itr.key () == curveName) {
37 return true;
38 }
39 }
40
41 return false;
42}
const int INNER_RADIUS_MIN
log4cpp::Category * mainCat
Definition Logger.cpp:14
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ currentCurvesAsString()

QString CurveNameList::currentCurvesAsString ( ) const

For debugging we dump the curve names.

Definition at line 44 of file CurveNameList.cpp.

45{
46 LOG4CPP_INFO_S ((*mainCat)) << "CurveNameList::currentCurvesAsString";
47
50
51 for (int row = 0; row < rowCount (); row++) {
52
53 QString curveCurrent = data (index (row, CURVE_NAME_LIST_COLUMN_CURRENT)).toString ();
55 unsigned int points = 0;
56 if (m_currentCurveToOriginalCurve.contains (curveCurrent)) {
57 curveOriginal = m_currentCurveToOriginalCurve [curveCurrent];
58 if (m_originalCurveToPointCount.contains (curveOriginal)) {
59
60 points = m_originalCurveToPointCount [curveOriginal];
61 }
62 }
63
64 str << "\n current=" << curveCurrent.toLatin1().data()
65 << " original=" << curveOriginal
66 << " points=" << points;
67 }
68
69 return out;
70}
@ CURVE_NAME_LIST_COLUMN_CURRENT
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
One row per curve name.

◆ currentCurveToOriginalCurve()

QString CurveNameList::currentCurveToOriginalCurve ( const QString & currentCurve) const

Return the original curve for the specified current curve.

Definition at line 72 of file CurveNameList.cpp.

73{
74 return m_currentCurveToOriginalCurve [currentCurve];
75}

◆ currentCurveToPointCount()

unsigned int CurveNameList::currentCurveToPointCount ( const QString & currentCurve) const

Return the point count for the specified current curve.

Definition at line 77 of file CurveNameList.cpp.

78{
79 QString originalCurve = m_currentCurveToOriginalCurve [currentCurve];
80
81 return m_originalCurveToPointCount [originalCurve];
82}

◆ flags()

Qt::ItemFlags CurveNameList::flags ( const QModelIndex & index) const
virtual

Override normal flags with additional editing flags.

Definition at line 122 of file CurveNameList.cpp.

123{
124 if (index.isValid ()) {
125
126 // Not root item. ItemIsDropEnabled is unwanted during dragging since dragged entry would overwrite
127 // another entry if user forgets to drop into the space between successive entries
128 return (QStandardItemModel::flags (index) |
129 Qt::ItemIsDragEnabled |
130 Qt::ItemIsEnabled |
131 Qt::ItemIsSelectable |
132 Qt::ItemIsEditable) & ~Qt::ItemIsDropEnabled;
133
134 } else {
135
136 // Root item
137 return QStandardItemModel::flags (index) |
138 Qt::ItemIsDropEnabled;
139
140 }
141}

◆ insertRow()

void CurveNameList::insertRow ( int row,
const QString & curveCurrent,
const QString & curveOriginal,
unsigned int pointCount )

Create a new entry at the specified row.

Definition at line 143 of file CurveNameList.cpp.

147{
148 LOG4CPP_DEBUG_S ((*mainCat)) << "CurveNameList::insertRow"
149 << " row=" <<row
150 << " curveCurrent=" << curveCurrent.toLatin1().data()
151 << " curveOriginal=" << curveOriginal.toLatin1().data()
152 << " points=" << pointCount;
153
155 QStandardItemModel::insertRow (row, item);
156
157 // Documentation for QAbstractItemModels says beginInsertRows/endInsertRows send off a rowsAboutToBeInserted signal
159 row,
160 row);
161
162 m_currentCurveToOriginalCurve [curveCurrent] = curveOriginal;
163 m_originalCurveToPointCount [curveOriginal] = pointCount;
164
165 endInsertRows ();
166}
virtual QStandardItem * item(int row, int column=0) const
Retrieve data from model.
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20

◆ item()

QStandardItem * CurveNameList::item ( int row,
int column = 0 ) const
virtual

Retrieve data from model.

Definition at line 168 of file CurveNameList.cpp.

169{
170 LOG4CPP_DEBUG_S ((*mainCat)) << "CurveNameList::item"
171 << " row=" << row;
172
174
175 return QStandardItemModel::item (row, column);
176}
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...

◆ numPointsForSelectedCurves()

unsigned int CurveNameList::numPointsForSelectedCurves ( const QList< unsigned int > & rowsSelected) const

Return the number of points associated with the selected curves, as specified by their row numbers.

Definition at line 178 of file CurveNameList.cpp.

179{
180 int numPoints = 0;
181 for (int i = 0; i < rowsSelected.count(); i++) {
182 int row = signed (rowsSelected [i]);
183
185 QString currentCurve = data (idx).toString ();
186 if (m_currentCurveToOriginalCurve.contains (currentCurve)) {
187
188 QString originalCurve = m_currentCurveToOriginalCurve [currentCurve];
189 if (m_originalCurveToPointCount.contains (originalCurve)) {
190
191 numPoints += m_originalCurveToPointCount [originalCurve];
192 }
193 }
194 }
195
196 return unsigned (numPoints);
197}

◆ removeRows()

bool CurveNameList::removeRows ( int row,
int count,
const QModelIndex & parent )
virtual

Remove one row.

Definition at line 199 of file CurveNameList.cpp.

202{
203 // LOG4CPP is below
204
205 bool skip = (count != 1 || row < 0 || row > rowCount () || parent.isValid());
206
208 if (!skip) {
209
211
212 // As documented for QAbstractItemModel, beginRemoveRows "emits the rowsAboutToBeRemoved() signal which connected views
213 // (or proxies) must handle before the data is removed. Otherwise, the views may end up in an invalid state."
215 row,
216 row + count - 1);
217
218 // We do not call QStandardItemModel::removeRow or QAbstractItemModel::removeRow here since that leads to an infinite loop when it calls this method
219 for (int rowRemove = row; rowRemove < row + count; rowRemove++) {
220 QStandardItemModel::removeRows (row,
221 count,
222 parent);
223 }
224
225 endRemoveRows ();
226
228 }
229
230 LOG4CPP_DEBUG_S ((*mainCat)) << "CurveNameList::removeRows"
231 << " row=" << 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();
237 return true;
238}
QString currentCurvesAsString() const
For debugging we dump the curve names.

◆ reset()

void CurveNameList::reset ( )

Clear all information.

Definition at line 240 of file CurveNameList.cpp.

241{
242 LOG4CPP_INFO_S ((*mainCat)) << "CurveNameList::reset";
243
244 clear();
245 m_currentCurveToOriginalCurve.clear();
246 m_originalCurveToPointCount.clear();
247}

◆ rowCount()

int CurveNameList::rowCount ( const QModelIndex & parent = QModelIndex()) const
virtual

One row per curve name.

Definition at line 249 of file CurveNameList.cpp.

250{
251 int count = QStandardItemModel::rowCount ();
252
253// LOG4CPP_DEBUG_S ((*mainCat)) << "CurveNameList::rowCount"
254// << " count=" << count;
255
256 return count;
257}

◆ setData()

bool CurveNameList::setData ( const QModelIndex & index,
const QVariant & value,
int role )
virtual

Store data for one curve name.

Definition at line 259 of file CurveNameList.cpp.

262{
263 LOG4CPP_DEBUG_S ((*mainCat)) << "CurveNameList::setData"
264 << " row=" << index.row()
265 << " value=" << value.toString().toLatin1().data()
266 << " role=" << roleAsString (role).toLatin1().data();
267
268 bool success;
269 if (role == Qt::EditRole) {
270
271 // Each curve name must be unique
272 if (curveNameIsAcceptable (value.toString(),
273 index.row())) {
274
275 // Curve name is fine
276 QModelIndex idxOld = QStandardItemModel::index (index.row(), CURVE_NAME_LIST_COLUMN_CURRENT);
277
278 // Old and new curve names
279 QString curveCurrentOld = data (idxOld).toString ();
280 QString curveCurrentNew = value.toString ();
281
282 // Remove old entry after saving original curve name
284 if (m_currentCurveToOriginalCurve.contains (curveCurrentOld)) {
285
286 // Remember old original curve name
287 curveOriginal = m_currentCurveToOriginalCurve [curveCurrentOld];
288
289 // Remove old entry
290 m_currentCurveToOriginalCurve.remove (curveCurrentOld);
291
292 // Add new entry
293 m_currentCurveToOriginalCurve [curveCurrentNew] = curveOriginal;
294 }
295
296 success = QStandardItemModel::setData (index,
297 value,
298 role);
299 } else {
300
301 // Curve name is unacceptable
302 success = false;
303
304 }
305 } else {
306
307 // For non-edits, this method just calls the superclass method
308 success = QStandardItemModel::setData (index,
309 value,
310 role);
311 }
312
313 return success;
314}
QString roleAsString(int role)

◆ setItem()

void CurveNameList::setItem ( int row,
int column,
QStandardItem * item )
virtual

Store one curve name data.

Definition at line 316 of file CurveNameList.cpp.

319{
320 // LOG4CPP is below
321
323
325
326 QStandardItemModel::setItem (row,
327 column,
328 item);
329
331
332 LOG4CPP_DEBUG_S ((*mainCat)) << "CurveNameList::setItem"
333 << " row=" << row
334 << " before=" << before.toLatin1().data()
335 << " after=" << after.toLatin1().data();
336}

◆ supportedDropActions()

Qt::DropActions CurveNameList::supportedDropActions ( ) const
virtual

Allow dragging for reordering.

Definition at line 338 of file CurveNameList.cpp.

339{
340 return Qt::MoveAction;
341}

The documentation for this class was generated from the following files: