7 #include "CallbackGatherXThetaValuesFunctions.h"
8 #include "CmdMediator.h"
10 #include "CurveConnectAs.h"
11 #include "CurveStyle.h"
12 #include "EngaugeAssert.h"
13 #include "GeometryModel.h"
14 #include "GeometryWindow.h"
16 #include <QApplication>
18 #include <QHeaderView>
19 #include <QItemSelectionModel>
21 #include <QTextStream>
26 const QString TokenName (QObject::tr (
"CurveName:"));
27 const QString TokenFunctionArea (QObject::tr (
"FunctionArea:"));
28 const QString TokenPolygonArea (QObject::tr (
"PolygonArea:"));
29 const QString TokenX (QObject::tr (
"X"));
30 const QString TokenY (QObject::tr (
"Y"));
31 const QString TokenIndex (QObject::tr (
"Index"));
32 const QString TokenDistanceGraph (QObject::tr (
"Distance"));
33 const QString TokenDistancePercent (QObject::tr (
"Percent"));
39 setAllowedAreas (Qt::AllDockWidgetAreas);
40 setWindowTitle (tr (
"Geometry Window"));
41 setStatusTip (tr (
"Geometry Window"));
42 setWhatsThis (tr (
"Geometry Window\n\n"
43 "This table displays the following geometry data for the currently selected curve:\n\n"
44 "Function area = Area under the curve if it is a function\n\n"
45 "Polygon area = Area inside the curve if it is a relation. This value is only correct "
46 "if none of the curve lines intersect each other\n\n"
47 "X = X coordinate of each point\n\n"
48 "Y = Y coordinate of each point\n\n"
49 "Index = Point number\n\n"
50 "Distance = Distance along the curve in forward or backward direction, in either graph units "
51 "or as a percentage"));
55 m_view =
new QTableView;
56 m_view->setModel (m_model);
57 m_view->horizontalHeader()->hide();
58 m_view->verticalHeader()->hide();
59 m_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
60 connect (m_view->selectionModel(), SIGNAL (selectionChanged (
const QItemSelection &,
const QItemSelection &)),
70 GeometryWindow::~GeometryWindow()
77 resizeTable (NUM_HEADER_ROWS);
80 for (
int row = 0; row < NUM_HEADER_ROWS - 1; row++) {
81 m_model->setItem (row, COLUMN_HEADER_VALUE,
new QStandardItem (
""));
87 LOG4CPP_INFO_S ((*mainCat)) <<
"GeometryWindow::closeEvent";
92 int GeometryWindow::fold2dIndexes (
int row,
98 return (row - rowLow) * (colHigh - colLow + 1) + (col - colLow);
103 return COLUMN_BODY_POINT_IDENTIFIERS;
106 void GeometryWindow::initializeHeader ()
108 LOG4CPP_INFO_S ((*mainCat)) <<
"GeometryWindow::initializeHeader";
110 resizeTable (NUM_HEADER_ROWS);
112 m_model->setItem (HEADER_ROW_NAME, COLUMN_HEADER_LABEL,
new QStandardItem (TokenName));
113 m_model->setItem (HEADER_ROW_FUNC_AREA, COLUMN_HEADER_LABEL,
new QStandardItem (TokenFunctionArea));
114 m_model->setItem (HEADER_ROW_POLY_AREA, COLUMN_HEADER_LABEL,
new QStandardItem (TokenPolygonArea));
115 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_X,
new QStandardItem (TokenX));
116 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_Y,
new QStandardItem (TokenY));
117 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_INDEX,
new QStandardItem (TokenIndex));
118 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_DISTANCE_GRAPH_FORWARD,
new QStandardItem (TokenDistanceGraph));
119 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_DISTANCE_PERCENT_FORWARD,
new QStandardItem (TokenDistancePercent));
120 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_DISTANCE_GRAPH_BACKWARD,
new QStandardItem (TokenDistanceGraph));
121 m_model->setItem (HEADER_ROW_COLUMN_NAMES, COLUMN_BODY_DISTANCE_PERCENT_BACKWARD,
new QStandardItem (TokenDistancePercent));
124 void GeometryWindow::loadStrategies ()
126 LOG4CPP_INFO_S ((*mainCat)) <<
"GeometryWindow::loadStrategies";
129 void GeometryWindow::resizeTable (
int rowCount)
131 LOG4CPP_INFO_S ((*mainCat)) <<
"GeometryWindow::resizeTable";
135 m_model->setRowCount (rowCount);
136 m_model->setColumnCount (NUM_BODY_COLUMNS);
151 const QItemSelection & )
153 const bool NOT_GNUPLOT =
false;
155 QItemSelectionModel *selectionModel = m_view->selectionModel ();
156 QModelIndexList selection = selectionModel->selectedIndexes ();
158 if (selection.size () > 0) {
161 int rowLow = 0, rowHigh = 0, colLow = 0, colHigh = 0;
163 for (QModelIndexList::const_iterator itr = selection.begin(); itr != selection.end(); itr++) {
164 QModelIndex index = *itr;
165 if (isFirst || index.row () < rowLow ) rowLow = index.row ();
166 if (isFirst || index.row () > rowHigh) rowHigh = index.row ();
167 if (isFirst || index.column () < colLow ) colLow = index.column ();
168 if (isFirst || index.column () > colHigh) colHigh = index.column ();
172 int numRows = rowHigh - rowLow + 1;
173 int numCols = colHigh - colLow + 1;
177 QVector<QString> table (numRows * numCols);
179 for (
int i = 0; i < selection.size (); i++) {
180 QModelIndex index = selection [i];
181 QVariant data = m_model->
data (index);
182 QString text = data.toString ();
183 table [fold2dIndexes (index.row(), index.column(), rowLow, colLow, colHigh)] = text;
188 QTextStream str (&output);
189 for (
int row = rowLow; row <= rowHigh; row++) {
191 for (
int col = colLow; col <= colHigh; col++) {
192 str << delimiter << table [fold2dIndexes (row, col, rowLow, colLow, colHigh)];
193 delimiter = exportDelimiterToText (m_modelExport.
delimiter(),
200 QApplication::clipboard ()->setText (output);
206 const QString &curveSelected,
209 LOG4CPP_INFO_S ((*mainCat)) <<
"GeometryWindow::update";
217 ENGAUGE_CHECK_PTR (curve);
219 const Points points = curve->
points();
221 QString funcArea, polyArea;
222 QVector<QString> x, y, distanceGraphForward, distancePercentForward, distanceGraphBackward, distancePercentBackward;
235 distanceGraphForward,
236 distancePercentForward,
237 distanceGraphBackward,
238 distancePercentBackward);
241 resizeTable (NUM_HEADER_ROWS + points.count());
243 m_model->setItem (HEADER_ROW_NAME, COLUMN_HEADER_VALUE,
new QStandardItem (curveSelected));
244 m_model->setItem (HEADER_ROW_FUNC_AREA, COLUMN_HEADER_VALUE,
new QStandardItem (funcArea));
245 m_model->setItem (HEADER_ROW_POLY_AREA, COLUMN_HEADER_VALUE,
new QStandardItem (polyArea));
247 if (transformation.transformIsDefined()) {
249 int row = NUM_HEADER_ROWS;
251 for (; index < points.count(); row++, index++) {
253 const Point &point = points.at (index);
256 transformation.transformScreenToRawGraph (point.
posScreen (),
259 m_model->setItem (row, COLUMN_BODY_X,
new QStandardItem (x [index]));
260 m_model->setItem (row, COLUMN_BODY_Y,
new QStandardItem (y [index]));
261 m_model->setItem (row, COLUMN_BODY_INDEX,
new QStandardItem (QString::number (index + 1)));
262 m_model->setItem (row, COLUMN_BODY_DISTANCE_GRAPH_FORWARD,
new QStandardItem (distanceGraphForward [index]));
263 m_model->setItem (row, COLUMN_BODY_DISTANCE_PERCENT_FORWARD,
new QStandardItem (distancePercentForward [index]));
264 m_model->setItem (row, COLUMN_BODY_DISTANCE_GRAPH_BACKWARD,
new QStandardItem (distanceGraphBackward [index]));
265 m_model->setItem (row, COLUMN_BODY_DISTANCE_PERCENT_BACKWARD,
new QStandardItem (distancePercentBackward [index]));
266 m_model->setItem (row, COLUMN_BODY_POINT_IDENTIFIERS,
new QStandardItem (point.
identifier()));
274 m_view->setColumnHidden (COLUMN_BODY_POINT_IDENTIFIERS,
true);
277 void GeometryWindow::unselectAll ()
279 QItemSelectionModel *selectionModel = m_view->selectionModel ();
281 selectionModel->clearSelection ();
void slotSelectionChanged(const QItemSelection &, const QItemSelection &)
Prepare for copy after selection has changed.
void setCurrentPointIdentifier(const QString &pointIdentifier)
Set the point identifier to be highlighted. Value is empty for no highlighting.
virtual void closeEvent(QCloseEvent *event)
Catch close event so corresponding menu item in MainWindow can be updated accordingly.
const Points points() const
Return a shallow copy of the Points.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Override for special processing.
LineStyle lineStyle() const
Get method for LineStyle.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
void slotPointHoverEnter(QString)
Highlight the row for the specified point.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
QPointF posScreen() const
Accessor for screen position.
void update(const CmdMediator &cmdMediator, const MainWindowModel &modelMainWindow, const QString &curveSelected, const Transformation &transformation)
Populate the table with the specified Curve.
QString identifier() const
Unique identifier for a specific Point.
void calculateGeometry(const Points &points, const DocumentModelCoords &modelCoords, const DocumentModelGeneral &modelGeneral, const MainWindowModel &modelMainWindow, const Transformation &transformation, CurveConnectAs connectAs, QString &funcArea, QString &polyArea, QVector< QString > &x, QVector< QString > &y, QVector< QString > &distanceGraphForward, QVector< QString > &distancePercentForward, QVector< QString > &distanceGraphBackward, QVector< QString > &distancePercentBackward) const
Calculate geometry parameters.
void slotPointHoverLeave(QString)
Unhighlight the row for the specified point.
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
Model for DlgSettingsMainWindow.
void signalGeometryWindowClosed()
Signal that this QDockWidget was just closed.
static int columnBodyPointIdentifiers()
Hidden column that has the point identifiers.
Container for LineStyle and PointStyle for one Curve.
Container for one set of digitized Points.
CurveStyle curveStyle(const QString &curveName) const
CurveStyle in specified curve.
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Model that adds row highlighting according to the currently select point identifier.
DocumentModelExportFormat modelExport() const
Get method for DocumentModelExportFormat.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
void clear()
Clear stale information.
GeometryWindow(QWidget *parent)
Single constructor. Parent is needed or else this widget cannot be redocked after being undocked...