6#include <QtCore/QMimeData>
7#include <QtCore/QByteArray>
8#include <QtCore/QAbstractTableModel>
9#include <QtGui/QDoubleValidator>
10#include <QtGui/QClipboard>
11#if QT_VERSION >= 0x050000
12#include <QtWidgets/QLineEdit>
14#include <QtGui/QLineEdit>
26#include <GeneratedFiles/iqt2d/ui_CPolygonParamsGuiComp.h>
33template <
class PolygonBasedShape,
class PolygonBasedModel>
36 Ui::CPolygonParamsGuiComp,
63 Ui::CPolygonParamsGuiComp,
68 I_ASSIGN(m_nodeListSizeAttrPtr,
"NodeListSize",
"Fixed height of the node list if set (0 - hide)",
false, 0);
69 I_ASSIGN(m_hideCopyPasteAttrPtr,
"HideCopyPaste",
"Hide Copy & Paste buttons",
true,
true);
83 virtual int rowCount(
const QModelIndex& parent = QModelIndex())
const override;
84 virtual int columnCount(
const QModelIndex& parent = QModelIndex())
const override;
85 virtual QVariant
data(
const QModelIndex& index,
int role = Qt::DisplayRole)
const override;
86 virtual bool setData(
const QModelIndex& index,
const QVariant& value,
int role = Qt::EditRole)
override;
87 virtual QVariant
headerData(
int section, Qt::Orientation orientation,
int role = Qt::DisplayRole)
const override;
88 virtual Qt::ItemFlags
flags(
const QModelIndex &index)
const override;
89 virtual bool removeRows(
int row,
int count,
const QModelIndex &parent = QModelIndex())
override;
91 using QAbstractTableModel::dataChanged;
92 using QAbstractTableModel::layoutChanged;
109 virtual int rowCount(
const QModelIndex& parent = QModelIndex())
const;
110 virtual int columnCount(
const QModelIndex& parent = QModelIndex())
const;
111 virtual QVariant
data(
const QModelIndex& index,
int role = Qt::DisplayRole)
const;
112 virtual bool setData(
const QModelIndex& index,
const QVariant& value,
int role = Qt::EditRole);
113 virtual QVariant
headerData(
int section, Qt::Orientation orientation,
int role = Qt::DisplayRole)
const;
114 virtual Qt::ItemFlags
flags(
const QModelIndex &index)
const;
128 static bool SetValue(
const QVariant& variant,
double& result);
129 static QVariant
GetValue(
double value,
int round = 2);
132 using BaseClass::GetObservedObject;
133 using BaseClass::GetObservedModel;
134 using BaseClass::DoUpdateModel;
136 using BaseClass::NodeParamsTable;
138 using BaseClass::GetQtWidget;
139 using BaseClass::RemoveButton;
140 using BaseClass::InsertButton;
141 using BaseClass::ToolsButton;
142 using BaseClass::CopyButton;
143 using BaseClass::PasteButton;
146 I_ATTR(
int, m_nodeListSizeAttrPtr);
147 I_ATTR(
bool, m_hideCopyPasteAttrPtr);
162template <
class PolygonBasedShape,
class PolygonBasedModel>
164: m_flipHorizontalAction(QIcon(
":/Icons/FlipHorizontal"),
"", this),
165 m_flipVerticalAction(QIcon(
":/Icons/FlipVertical"),
"", this),
166 m_rotateCwAction(QIcon(
":/Icons/RotateRight"),
"", this),
167 m_rotateCcwAction(QIcon(
":/Icons/RotateLeft"),
"", this),
168 m_reversePolarityAction(QIcon(
":/Icons/Reverse"),
"", this),
176template <
class PolygonBasedShape,
class PolygonBasedModel>
179 return NodeParamsTable;
183template <
class PolygonBasedShape,
class PolygonBasedModel>
187 if (objectPtr !=
NULL){
188 QItemSelectionModel *select = NodeParamsTable->selectionModel();
189 QModelIndexList selected = select->selectedRows();
191 int row = selected.isEmpty()? -1: selected.front().row();
202template <
class PolygonBasedShape,
class PolygonBasedModel>
205 PolygonBasedModel* objectPtr = GetObservedObject();
206 if (objectPtr ==
NULL){
212 if (objectPtr->Serialize(archive)){
215 QMimeData* dataPtr =
new QMimeData();
216 dataPtr->setData(
typeid (PolygonBasedModel).name(), data);
218 QApplication::clipboard()->setMimeData(dataPtr);
223template <
class PolygonBasedShape,
class PolygonBasedModel>
226 PolygonBasedModel* objectPtr = GetObservedObject();
227 if (objectPtr ==
NULL){
231 const QMimeData* dataPtr = QApplication::clipboard()->mimeData();
232 if (dataPtr !=
NULL){
233 if (dataPtr->hasFormat(typeid (PolygonBasedModel).name())){
234 QByteArray data(dataPtr->data(typeid (PolygonBasedModel).name()));
238 objectPtr->Serialize(archive);
244template <
class PolygonBasedShape,
class PolygonBasedModel>
248 if (objectPtr !=
NULL){
249 QItemSelectionModel *select = NodeParamsTable->selectionModel();
250 QModelIndexList selected = select->selectedRows();
252 int row = selected.isEmpty()? -1: selected.front().row();
254 m_tableModel.removeRows(row, 1);
262template <
class PolygonBasedShape,
class PolygonBasedModel>
268 if (objectPtr !=
NULL){
276template <
class PolygonBasedShape,
class PolygonBasedModel>
283template <
class PolygonBasedShape,
class PolygonBasedModel>
286 if ((role == Qt::DisplayRole) || (role == Qt::EditRole)){
289 if ((objectPtr !=
NULL) && (index.column() <= 1) && (index.column() >= 0)){
292 return GetValue(retVal[index.column()]);
300template <
class PolygonBasedShape,
class PolygonBasedModel>
303 if (role != Qt::EditRole || index.column() < 0 || index.column() > 1 || index.row() < 0)
311 if (SetValue(value, pos[index.column()])) {
320template <
class PolygonBasedShape,
class PolygonBasedModel>
323 if (orientation == Qt::Horizontal){
324 if (role == Qt::DisplayRole){
339template <
class PolygonBasedShape,
class PolygonBasedModel>
342 return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
348template <
class PolygonBasedShape,
class PolygonBasedModel>
351 BaseClass::OnGuiCreated();
353 NodeParamsTable->setModel(&m_tableModel);
355 if (*m_hideCopyPasteAttrPtr){
360 bool isNodeTable =
true;
361 if (m_nodeListSizeAttrPtr.IsValid()){
362 if (*m_nodeListSizeAttrPtr > 0){
363 NodeParamsTable->setFixedHeight(qMax(40, *m_nodeListSizeAttrPtr));
366 InsertButton->hide();
367 RemoveButton->hide();
368 NodeParamsTable->hide();
372 GetQtWidget()->adjustSize();
376#if QT_VERSION < 0x050000
377 NodeParamsTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
379 NodeParamsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
384 CreateToolsMenu(ToolsButton);
388template <
class PolygonBasedShape,
class PolygonBasedModel>
391 BaseClass::OnGuiRetranslate();
393 m_flipHorizontalAction.setText(QCoreApplication::translate(
"iqt2d",
"Flip horizontally"));
394 m_flipVerticalAction.setText(QCoreApplication::translate(
"iqt2d",
"Flip vertically"));
395 m_rotateCwAction.setText(QCoreApplication::translate(
"iqt2d",
"Rotate clockwise"));
396 m_rotateCcwAction.setText(QCoreApplication::translate(
"iqt2d",
"Rotate counterclockwise"));
397 m_reversePolarityAction.setText(QCoreApplication::translate(
"iqt2d",
"Reverse line"));
401template <
class PolygonBasedShape,
class PolygonBasedModel>
404 BaseClass::OnGuiDesignChanged();
406 CopyButton->setIcon(this->GetIcon(
":/Icons/Copy"));
407 PasteButton->setIcon(this->GetIcon(
":/Icons/Paste"));
408 InsertButton->setIcon(this->GetIcon(
":/Icons/Add"));
409 RemoveButton->setIcon(this->GetIcon(
":/Icons/Delete"));
410 ToolsButton->setIcon(this->GetIcon(
":/Icons/Tools"));
416template <
class PolygonBasedShape,
class PolygonBasedModel>
419 if (!BaseClass::PopulateActions(host, modelPtr)){
424 if (polygonPtr ==
nullptr){
428 host.addAction(&m_flipHorizontalAction);
429 host.addAction(&m_flipVerticalAction);
430 host.addAction(&m_rotateCwAction);
431 host.addAction(&m_rotateCcwAction);
434 host.addAction(&m_reversePolarityAction);
441template <
class PolygonBasedShape,
class PolygonBasedModel>
446 PolygonBasedModel* modelPtr =
dynamic_cast<PolygonBasedModel*
>(BaseClass::GetObservedModel());
449 if (actionPtr ==
NULL || modelPtr ==
NULL){
453 if (actionPtr == &m_flipHorizontalAction){
456 else if (actionPtr == &m_flipVerticalAction){
459 else if (actionPtr == &m_rotateCwAction){
460 modelPtr->Rotate(M_PI/2);
462 else if (actionPtr == &m_rotateCcwAction){
463 modelPtr->Rotate(-M_PI/2);
465 else if (actionPtr == &m_reversePolarityAction){
466 modelPtr->ReverseNodes();
473template <
class PolygonBasedShape,
class PolygonBasedModel>
476 QModelIndex leftTop = m_tableModel.index(0, 0);
477 QModelIndex rightBottom = m_tableModel.index(rowCount() - 1, columnCount() - 1);
479 Q_EMIT m_tableModel.dataChanged(leftTop, rightBottom);
480 Q_EMIT m_tableModel.layoutChanged();
482 BaseClass::UpdateGui(changeSet);
486template <
class PolygonBasedShape,
class PolygonBasedModel>
490 double res = variant.toDouble(&ok);
500template <
class PolygonBasedShape,
class PolygonBasedModel>
507 double p = pow(10.0, round);
508 return qRound(value * p)/p;
514template <
class PolygonBasedShape,
class PolygonBasedModel>
516: m_parentPtr(parentPtr)
523template <
class PolygonBasedShape,
class PolygonBasedModel>
526 if (m_parentPtr !=
NULL){
527 return m_parentPtr->rowCount(parent);
534template <
class PolygonBasedShape,
class PolygonBasedModel>
537 if (m_parentPtr !=
NULL){
538 return m_parentPtr->columnCount(parent);
545template <
class PolygonBasedShape,
class PolygonBasedModel>
548 if (m_parentPtr !=
NULL){
549 return m_parentPtr->data(index, role);
556template <
class PolygonBasedShape,
class PolygonBasedModel>
559 if (m_parentPtr !=
NULL){
560 return m_parentPtr->setData(index, value, role);
567template <
class PolygonBasedShape,
class PolygonBasedModel>
570 if (m_parentPtr !=
NULL){
571 return m_parentPtr->headerData(section, orientation, role);
578template <
class PolygonBasedShape,
class PolygonBasedModel>
581 if (m_parentPtr !=
NULL){
582 return m_parentPtr->flags(index);
585 return Qt::ItemIsSelectable;
588template <
class PolygonBasedShape,
class PolygonBasedModel>
591 Q_EMIT beginRemoveRows(parent, row, row + count - 1);
594 if (objectPtr !=
NULL){
598 Q_EMIT endRemoveRows();
Definition of the data model for a polygon.
2D-object representing a polyline.
virtual bool InsertNode(const i2d::CVector2d &position)
Insert a node at the end of node table.
virtual const i2d::CVector2d & GetNodePos(int index) const
Return position of node at specified index.
virtual void SetNodePos(int index, const i2d::CVector2d &position)
Set node at specified index.
virtual int GetNodesCount() const
Return size of node table.
virtual bool RemoveNode(int index)
Remove a node at specified index.
Definition of position or mathematical vector on 2D plane.
static const CVector2d & GetZero()
Common interface for model objects, that supports Model/Observer design pattern.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const override
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QAbstractTableModel BaseClass
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
TableModel(TPolygonBasedParamsGuiComp< PolygonBasedShape, PolygonBasedModel > *parentPtr)
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
QAction m_flipVerticalAction
virtual void OnActionTriggered(QAction *actionPtr) override
@ CI_LAST
Last used cell index.
@ CI_Y
Index of the table cell for the X coordinate of the polygon node.
@ CI_X
Index of the table cell for the X coordinate of the polygon node.
virtual void OnGuiDesignChanged() override
virtual void OnInsertNode()
static QVariant GetValue(double value, int round=2)
virtual void OnCopyData()
QAction m_flipHorizontalAction
iqt2d::TShapeParamsGuiCompBase< Ui::CPolygonParamsGuiComp, PolygonBasedShape, PolygonBasedModel > BaseClass
virtual bool PopulateActions(QWidget &host, imod::IModel *modelPtr) override
virtual void UpdateGui(const istd::IChangeable::ChangeSet &changeSet) override
QAction m_rotateCcwAction
virtual void OnPasteData()
TPolygonBasedParamsGuiComp()
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
virtual void OnGuiCreated() override
QTableView * GetNodeTable()
Get the table with the node data.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual void OnGuiRetranslate() override
static bool SetValue(const QVariant &variant, double &result)
virtual void OnRemoveNode()
QAction m_reversePolarityAction
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
virtual void CreateToolsMenu(QAbstractButton *buttonPtr)
Implementation of archive using memory buffer to read the persistent objects.
Implementation of archive using memory buffer to store the persistent objects.
int GetBufferSize() const
const void * GetBuffer() const
Set of change flags (its IDs).
This package contains Qt based implementations for 2D graphic objects.