Engauge Digitizer  2
Public Member Functions | List of all members
GeometryModel Class Reference

Model that adds row highlighting according to the currently select point identifier. More...

#include <GeometryModel.h>

Inheritance diagram for GeometryModel:
Inheritance graph
Collaboration diagram for GeometryModel:
Collaboration graph

Public Member Functions

 GeometryModel ()
 Single constructor. More...
 
virtual ~GeometryModel ()
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Override for special processing. More...
 
void setCurrentPointIdentifier (const QString &pointIdentifier)
 Set the point identifier to be highlighted. Value is empty for no highlighting. More...
 
void setPotentialExportAmbiguity (const QVector< bool > &isPotentialExportAmbiguity)
 Remember which rows could have ambiguities during export - these will be highlighted. More...
 
- Public Member Functions inherited from WindowModelBase
 WindowModelBase ()
 Single constructor. More...
 
virtual ~WindowModelBase ()
 
QMimeData * mimeData (const QModelIndexList &indexes) const
 Support dragging of multiple cells. More...
 
QString selectionAsHtml () const
 Convert the selection into exportable html which is good for spreadsheets. More...
 
QString selectionAsText (ExportDelimiter delimiter) const
 Convert the selection into exportable text which is good for text editors. More...
 
void setDelimiter (ExportDelimiter delimiter)
 Save output delimiter. More...
 
void setView (WindowTable &view)
 Save the view so this class can access the current selection. More...
 

Detailed Description

Model that adds row highlighting according to the currently select point identifier.

Definition at line 16 of file GeometryModel.h.

Constructor & Destructor Documentation

◆ GeometryModel()

GeometryModel::GeometryModel ( )

Single constructor.

Definition at line 14 of file GeometryModel.cpp.

14  :
15  m_rowToBeHighlighted (NO_HIGHLIGHTED_ROW)
16 {
17 }
const int NO_HIGHLIGHTED_ROW

◆ ~GeometryModel()

GeometryModel::~GeometryModel ( )
virtual

Definition at line 19 of file GeometryModel.cpp.

20 {
21 }

Member Function Documentation

◆ data()

QVariant GeometryModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

Override for special processing.

Definition at line 23 of file GeometryModel.cpp.

24 {
25  const int HEADER_OFFSET = 1;
26  const int NUM_LEGEND_ROWS_UNSPANNED = 2; // Match with GeometryWindow::NUM_LEGEND_ROWS_UNSPANNED
27 
28 // LOG4CPP_DEBUG_S ((*mainCat)) << "GeometryModel::data"
29 // << " rowHighlighted=" << m_rowToBeHighlighted
30 // << " index=(row=" << index.row() << ",col=" << index.column() << ",role=" << role << ")="
31 // << " rows=" << rowCount()
32 // << " cols=" << columnCount();
33 
34  if ((role == Qt::BackgroundRole) &&
35  !m_pointIdentifier.isEmpty () &&
36  (index.row () == m_rowToBeHighlighted)) {
37 
38  // This row is to be highlighted with gray
39  return QVariant (QColor (230, 230, 230));
40  }
41 
42  bool ambiguousSegment = ((role == Qt::BackgroundRole) &&
43  (m_ambiguousRows.contains (index.row () - HEADER_OFFSET)));
44  bool ambiguousFootnote = ((role == Qt::BackgroundRole) &&
45  (m_ambiguousRows.size () > 0) &&
46  (index.row () >= rowCount () - NUM_LEGEND_ROWS_UNSPANNED));
47  if (ambiguousSegment || ambiguousFootnote) {
48 
49  // This row is to be highlighted with light red. Note that gray color preempts this behavior
50  return QVariant (QColor (255, 0, 0, 50));
51  }
52 
53  // Standard behavior
54  return QStandardItemModel::data (index, role);
55 }

◆ setCurrentPointIdentifier()

void GeometryModel::setCurrentPointIdentifier ( const QString &  pointIdentifier)

Set the point identifier to be highlighted. Value is empty for no highlighting.

Definition at line 83 of file GeometryModel.cpp.

84 {
85  LOG4CPP_INFO_S ((*mainCat)) << "GeometryModel::setCurrentPointIdentifier"
86  << " rows=" << rowCount()
87  << " cols=" << columnCount()
88  << " identifier=" << pointIdentifier.toLatin1().data();
89 
90  m_pointIdentifier = pointIdentifier;
91 
92  int rowTransitioned;
93  if (!m_pointIdentifier.isEmpty ()) {
94 
95  // Get new row. It will transition from unhighlighted to highlighted
96  m_rowToBeHighlighted = rowToBeHighlighted();
97  rowTransitioned = m_rowToBeHighlighted;
98 
99  } else {
100 
101  // Old row will transition from highlighted to unhighlighted
102  rowTransitioned = m_rowToBeHighlighted;
103  m_rowToBeHighlighted = NO_HIGHLIGHTED_ROW;
104 
105  }
106 
107  QModelIndex indexTopLeft = createIndex (rowTransitioned, 0);
108  QModelIndex indexBottomRight = createIndex (rowTransitioned, columnCount() - 1);
109 
110  QVector<int> roles;
111  roles << Qt::BackgroundRole;
112 
113  emit dataChanged (indexTopLeft,
114  indexBottomRight,
115  roles);
116 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
const int NO_HIGHLIGHTED_ROW
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ setPotentialExportAmbiguity()

void GeometryModel::setPotentialExportAmbiguity ( const QVector< bool > &  isPotentialExportAmbiguity)

Remember which rows could have ambiguities during export - these will be highlighted.

Definition at line 118 of file GeometryModel.cpp.

119 {
120  // Save row numbers with ambiguities
121  m_ambiguousRows.clear ();
122  for (int i = 0; i < isPotentialExportAmbiguity.size (); i++) {
123  if (isPotentialExportAmbiguity.at (i)) {
124  m_ambiguousRows [i] = true;
125  }
126  }
127 }

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