Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
WindowModelBase Class Reference

Model for WindowTable. More...

#include <WindowModelBase.h>

Inheritance diagram for WindowModelBase:
Inheritance graph
Collaboration diagram for WindowModelBase:
Collaboration graph

Public Member Functions

 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 for WindowTable.

Definition at line 18 of file WindowModelBase.h.

Constructor & Destructor Documentation

WindowModelBase::WindowModelBase ( )

Single constructor.

Definition at line 16 of file WindowModelBase.cpp.

16  :
17  m_view (nullptr)
18 {
19 }
WindowModelBase::~WindowModelBase ( )
virtual

Definition at line 21 of file WindowModelBase.cpp.

22 {
23 }

Member Function Documentation

QMimeData * WindowModelBase::mimeData ( const QModelIndexList &  indexes) const

Support dragging of multiple cells.

Without this only one cell can be copied by dragging. Clipboard copying is handled elsewhere in the window class

Definition at line 34 of file WindowModelBase.cpp.

35 {
36  if (indexes.isEmpty ()) {
37  return nullptr;
38  }
39 
40  QMimeData *data = new QMimeData ();
41 
42  data->setHtml (selectionAsHtml ());
43  data->setText (selectionAsText (m_delimiter));
44 
45  return data;
46 }
QString selectionAsHtml() const
Convert the selection into exportable html which is good for spreadsheets.
QString selectionAsText(ExportDelimiter delimiter) const
Convert the selection into exportable text which is good for text editors.
QString WindowModelBase::selectionAsHtml ( ) const

Convert the selection into exportable html which is good for spreadsheets.

Definition at line 48 of file WindowModelBase.cpp.

49 {
50  ENGAUGE_CHECK_PTR (m_view);
51 
52  int rowLow, colLow, rowHigh, colHigh;
53  QVector<QString> table;
54 
55  // Get raw data as a rectangular table. Size may be zero
56  selectionAsTable (rowLow,
57  colLow,
58  rowHigh,
59  colHigh,
60  table);
61 
62  // Concatenate table into output string
63  QString html;
64  QTextStream str (&html);
65 
66  str << "<table>";
67  for (int row = rowLow; row <= rowHigh; row++) {
68  str << "<tr>";
69  for (int col = colLow; col <= colHigh; col++) {
70  str << "<td>" << table [fold2dIndexes (row, col, rowLow, colLow, colHigh)] << "</td>";
71  }
72  str << "<tr>\n";
73  }
74  str << "</table>";
75 
76  return html;
77 }
#define ENGAUGE_CHECK_PTR(ptr)
#endif
Definition: EngaugeAssert.h:27
QString WindowModelBase::selectionAsText ( ExportDelimiter  delimiter) const

Convert the selection into exportable text which is good for text editors.

Definition at line 132 of file WindowModelBase.cpp.

133 {
134  const bool NOT_GNUPLOT = false;
135 
136  ENGAUGE_CHECK_PTR (m_view);
137 
138  int rowLow, colLow, rowHigh, colHigh;
139  QVector<QString> table;
140 
141  // Get raw data as a rectangular table. Size may be zero
142  selectionAsTable (rowLow,
143  colLow,
144  rowHigh,
145  colHigh,
146  table);
147 
148  // Concatenate table into output string
149  QString text;
150  QTextStream str (&text);
151  for (int row = rowLow; row <= rowHigh; row++) {
152  QString delimiterStr;
153  for (int col = colLow; col <= colHigh; col++) {
154  str << delimiterStr << table [fold2dIndexes (row, col, rowLow, colLow, colHigh)];
155  delimiterStr = exportDelimiterToText (delimiter,
156  NOT_GNUPLOT);
157  }
158  str << "\n";
159  }
160 
161  return text;
162 }
#define ENGAUGE_CHECK_PTR(ptr)
#endif
Definition: EngaugeAssert.h:27
QString exportDelimiterToText(ExportDelimiter exportDelimiter, bool isGnuplotDelimiter)
void WindowModelBase::setDelimiter ( ExportDelimiter  delimiter)

Save output delimiter.

Definition at line 164 of file WindowModelBase.cpp.

165 {
166  m_delimiter = delimiter;
167 }
void WindowModelBase::setView ( WindowTable view)

Save the view so this class can access the current selection.

Definition at line 169 of file WindowModelBase.cpp.

170 {
171  m_view = &view;
172 }

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