9 #include <QItemSelectionModel>
12 #include <QTextStream>
25 int WindowModelBase::fold2dIndexes (
int row,
31 return (row - rowLow) * (colHigh - colLow + 1) + (col - colLow);
36 if (indexes.isEmpty ()) {
40 QMimeData *data =
new QMimeData ();
52 int rowLow, colLow, rowHigh, colHigh;
53 QVector<QString> table;
56 selectionAsTable (rowLow,
64 QTextStream str (&html);
67 for (
int row = rowLow; row <= rowHigh; row++) {
69 for (
int col = colLow; col <= colHigh; col++) {
70 str <<
"<td>" << table [fold2dIndexes (row, col, rowLow, colLow, colHigh)] <<
"</td>";
79 void WindowModelBase::selectionAsTable (
int &rowLow,
83 QVector<QString> &table)
const
88 QItemSelectionModel *selectionModel = m_view->selectionModel ();
89 QModelIndexList selection = selectionModel->selectedIndexes ();
91 if (selection.size () > 0) {
99 for (QModelIndexList::const_iterator itr = selection.begin(); itr != selection.end(); itr++) {
100 QModelIndex index = *itr;
101 if (isFirst || index.row () < rowLow ) rowLow = index.row ();
102 if (isFirst || index.row () > rowHigh) rowHigh = index.row ();
103 if (isFirst || index.column () < colLow ) colLow = index.column ();
104 if (isFirst || index.column () > colHigh) colHigh = index.column ();
108 int numRows = rowHigh - rowLow + 1;
109 int numCols = colHigh - colLow + 1;
113 table.resize (numRows * numCols);
115 for (
int i = 0; i < selection.size (); i++) {
116 QModelIndex index = selection [i];
117 QVariant d = data (index);
118 QString text = d.toString ();
119 table [fold2dIndexes (index.row(), index.column(), rowLow, colLow, colHigh)] = text;
134 const bool NOT_GNUPLOT =
false;
138 int rowLow, colLow, rowHigh, colHigh;
139 QVector<QString> table;
142 selectionAsTable (rowLow,
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)];
166 m_delimiter = delimiter;
virtual ~WindowModelBase()
ExportDelimiter
Delimiter values that may or may not be overridden by DOCUMENT_SERIALIZE_EXPORT_DELIMITER_OVERRIDE_CS...
QString selectionAsHtml() const
Convert the selection into exportable html which is good for spreadsheets.
#define ENGAUGE_CHECK_PTR(ptr)
#endif
QString selectionAsText(ExportDelimiter delimiter) const
Convert the selection into exportable text which is good for text editors.
void setView(WindowTable &view)
Save the view so this class can access the current selection.
void setDelimiter(ExportDelimiter delimiter)
Save output delimiter.
Table view class with support for both drag-and-drop and copy-and-paste.
QString exportDelimiterToText(ExportDelimiter exportDelimiter, bool isGnuplotDelimiter)
WindowModelBase()
Single constructor.
QMimeData * mimeData(const QModelIndexList &indexes) const
Support dragging of multiple cells.