4#pragma warning(disable : 4800)
5#pragma warning(disable : 4251)
6#pragma warning(disable : 4244)
7#pragma warning(disable : 4127)
9#include <QStyledItemDelegate>
10#include <QSignalMapper>
12#include <QApplication>
17#include "../global.hpp"
18#include "../genapi/node_map.hpp"
19#include "../genapi/genapi.hpp"
20#include "_detail/detail_property_model.hpp"
30 class VariantDelegate :
public QStyledItemDelegate
36 explicit VariantDelegate(QObject *parent = 0)
37 : QStyledItemDelegate(parent)
38 , finishedMapper_(nullptr)
40 finishedMapper_ =
new QSignalMapper(
this);
41 QObject::connect(finishedMapper_, SIGNAL(mapped(QWidget *)),
this, SIGNAL(commitData(QWidget *)));
42 QObject::connect(finishedMapper_, SIGNAL(mapped(QWidget *)),
this, SIGNAL(closeEditor(QWidget *)));
45 QWidget *createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
46 const QModelIndex &index)
const override
50 auto prop =
static_cast<UI::Private::Property *
>(index.internalPointer());
55 case UI::Private::Property::PT_Boolean:
56 case UI::Private::Property::PT_Category:
57 case UI::Private::Property::PT_Command:
58 case UI::Private::Property::PT_Enumeration:
59 case UI::Private::Property::PT_Float:
60 case UI::Private::Property::PT_Integer:
61 case UI::Private::Property::PT_String:
62 editor = prop->CreateEditor(parent);
65 if (editor->metaObject()->indexOfSignal(
"editingFinished()") != -1)
67 QObject::connect(editor, SIGNAL(editingFinished()), finishedMapper_, SLOT(map()));
68 finishedMapper_->setMapping(editor, editor);
75 editor = QStyledItemDelegate::createEditor(parent, option, index);
82 void setEditorData(QWidget * ,
const QModelIndex & )
const override
87 void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index)
const override
89 auto data = index.model()->data(index, Qt::EditRole);
90 if (data.type() == QVariant::UserType)
92 data =
static_cast<UI::Private::Property *
>(index.internalPointer())->EditorData(editor);
95 model->setData(index, data, Qt::EditRole);
99 QStyledItemDelegate::setModelData(editor, model, index);
102 void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option,
103 const QModelIndex &index)
const override
105 return QStyledItemDelegate::updateEditorGeometry(editor, option, index);
108 void paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const override
111 painter->setPen(QColor(Qt::gray));
113 auto prop =
static_cast<UI::Private::Property *
>(index.internalPointer());
114 if (prop->Type() == UI::Private::Property::PT_Category)
116 painter->fillRect(option.rect,
117 QApplication::palette(
"QTreeView").brush(QPalette::Normal, QPalette::Button).color());
121 if (index.column() == 0)
122 painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
125 painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
128 QStyledItemDelegate::paint(painter, option, index);
132 QSignalMapper *finishedMapper_;
163 , propertyModel_(nullptr)
164 , updateTimer_(nullptr)
167 setSelectionMode(QAbstractItemView::SingleSelection);
168 setContextMenuPolicy(Qt::CustomContextMenu);
170 propertyModel_ =
new UI::Private::PropertyModel();
178 delete propertyModel_;
183 QObject::connect(
this, QOverload<const QModelIndex &>::of(&PropertyGrid::clicked),
184 [=](
const QModelIndex &index) {
187 auto prop = propertyModel_->Property(index);
190 if (!prop->IsReadOnly() && prop->Type() != UI::Private::Property::PT_Boolean)
196 updateTimer_ =
new QTimer(
this);
197 QObject::connect(updateTimer_, &QTimer::timeout, [=]() { update(); });
207 delete propertyModel_;
217 propertyModel_->SetNodeMap(nodemap);
219 setModel(propertyModel_);
220 setItemDelegate(
new VariantDelegate(
this));
221 resizeColumnToContents(0);
223 if (columnWidth(0) < maxColumnWidth_)
224 setColumnWidth(0, maxColumnWidth_);
234 return propertyModel_->NodeMap();
243 propertyModel_->RemoveNodeMap();
254 propertyModel_->SetMaxVisibility(visibility);
264 return propertyModel_->MaxVisibility();
275 return HtmlDescription(index);
285 QModelIndexList
Search(
const QString &text)
287 return propertyModel_->Search(text);
285 QModelIndexList
Search(
const QString &text) {
…}
296 propertyModel_->ResetSearch();
306 return propertyModel_->SearchText();
316 propertyModel_->SetSearchResultBGColor(color);
326 return propertyModel_->SearchResultBGColor();
337 return propertyModel_->Item(index)->Node();
347 for (
int i = 0; i < indexList.size(); i++)
348 ExpandProperty(indexList.at(i));
358 for (
int i = 0; i < indexList.size(); i++)
359 CollapseProperty(indexList.at(i));
369 propertyModel_->UpdateProperty(index);
378 propertyModel_->Update();
388 updateTimer_->start(ms);
397 updateTimer_->stop();
409 propertyModel_->ResetUpdateLock();
413 void ExpandProperty(
const QModelIndex &index)
416 setExpanded(index,
true);
420 auto parentIndex = propertyModel_->parent(index);
422 if (parentIndex != QModelIndex())
423 ExpandProperty(parentIndex);
426 void CollapseProperty(
const QModelIndex &index)
429 setExpanded(index,
false);
432 auto parentIndex = propertyModel_->parent(index);
434 if (parentIndex != QModelIndex())
435 CollapseProperty(parentIndex);
438 QString HtmlDescription(
const QModelIndex &index)
440 auto prop = propertyModel_->Item(index);
445 auto node = prop->Node();
448 if (!node->Description().empty())
449 txt.append(
"<br>" +
UI::CvbToQt(node->Description()));
451 txt.append(
"<br><table>");
452 txt.append(
"<tr><td><b>Full Name:</b></td><td>" +
UI::CvbToQt(node->Name()));
456 txt.append(
"<tr><td><b>Type:</b></td><td>" +
UI::CvbToQt(prop->NodeType()) +
"</td></tr>");
457 txt.append(
"<tr><td><b>Access Mode:</b></td><td>" +
UI::CvbToQt(prop->NodeAccessMode()) +
"</td></tr>");
458 txt.append(
"<tr><td><b>Visibility:</b></td><td>" +
UI::CvbToQt(prop->NodeVisibility()) +
"</td></tr>");
459 txt.append(
"<tr><td><b>Caching Mode:</b></td><td>" +
UI::CvbToQt(prop->NodeCachingMode()) +
"</td></tr>");
460 if (prop->NodeIsStreamable())
461 txt.append(
"<tr><td><b>Streamable:</b></td><td>True</td></tr>");
463 txt.append(
"<tr><td><b>Streamable:</b></td><td>False</td></tr>");
465 txt.append(
"</table>");
467 switch (prop->Type())
471 case UI::Private::Property::PropertyType::PT_Integer:
472 case UI::Private::Property::PropertyType::PT_Float:
473 case UI::Private::Property::PropertyType::PT_String:
474 case UI::Private::Property::PropertyType::PT_Enumeration:
475 txt.append(prop->HtmlDescription());
483 static const int maxColumnWidth_ = 180;
484 UI::Private::PropertyModel *propertyModel_;
485 QTimer *updateTimer_;
View to display a device's nodemap.
Definition property_grid.hpp:150
void StopAutoUpdate()
Stops the automatic update of the nodes.
Definition property_grid.hpp:395
NodePtr Node(const QModelIndex &index)
The node of the given QModelIndex.
Definition property_grid.hpp:335
void CollapseSearchResult(const QModelIndexList &indexList)
Collapses all nodes of given QModelIndexList as well as its parents.
Definition property_grid.hpp:356
NodeMapPtr NodeMap()
Return the nodemap.
Definition property_grid.hpp:232
GenApi::Visibility Visibility()
Returns the visibility of the nodemap.
Definition property_grid.hpp:262
void ReleaseNodeMap()
Release the nodemap.
Definition property_grid.hpp:241
void UpdateProperty(const QModelIndex &index)
Updates a given property / node.
Definition property_grid.hpp:367
QString SearchText()
Returns the search text which is currently set.
Definition property_grid.hpp:304
void SetVisibility(GenApi::Visibility visibility)
Set the visibility of the nodemap.
Definition property_grid.hpp:252
QModelIndexList Search(const QString &text)
Search for displayed property name.
Definition property_grid.hpp:285
QColor SearchResultBackgroundColor()
Returns the search result background color.
Definition property_grid.hpp:324
void StartAutoUpdate(int ms)
Starts the automatic update of the nodes.
Definition property_grid.hpp:386
void SetNodeMap(const NodeMapPtr &nodemap)
Set the nodemap and exchanges the model.
Definition property_grid.hpp:215
void ExpandSearchResult(const QModelIndexList &indexList)
Expands all nodes of given QModelIndexList as well as its parents.
Definition property_grid.hpp:345
QString HtmlFormattedDescription(const QModelIndex &index)
Returns an HTML formatted description of given node by QModelIndex.
Definition property_grid.hpp:273
PropertyGrid(const NodeMapPtr &nodemap, QWidget *parent=nullptr)
Create a property grid.
Definition property_grid.hpp:161
void SetSearchResultBackgroundColor(QColor color)
Set the search result background color.
Definition property_grid.hpp:314
void ResetUpdateLock()
Reset the update lock.
Definition property_grid.hpp:407
void ResetSearch()
Reset the search text.
Definition property_grid.hpp:294
void Update()
Updates all properties / nodes.
Definition property_grid.hpp:376
std::shared_ptr< Node > NodePtr
Convenience shared pointer for Node.
Definition genapi.hpp:71
Visibility
Feature complexity level.
Definition genapi.hpp:238
std::shared_ptr< NodeMap > NodeMapPtr
Convenience shared pointer for NodeMap.
Definition genapi.hpp:27
std::shared_ptr< CategoryNode > CategoryNodePtr
Convenience shared pointer for CategoryNode.
Definition genapi.hpp:35
Namespace for user interface components.
Definition decl_image_scene.hpp:39
QString CvbToQt(const Cvb::String &text) noexcept
Convenience converter for strings.
Definition ui.hpp:257
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17