25 #include <QDataWidgetMapper>
27 #include <QGridLayout>
51 auto result = std::make_unique<QLabel>(view_item->
data(Qt::DisplayRole).toString());
52 result->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
62 m_delegate->setEditorData(editor.get(), index);
65 editor->setEnabled(
view_model->sessionItemFromIndex(index)->isEnabled());
73 auto on_data_change = [
this](
const QModelIndex& topLeft,
const QModelIndex&,
74 const QVector<int>& roles) {
75 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
80 if (roles == expected_roles) {
81 auto view_item =
view_model->viewItemFromIndex(topLeft);
84 it->second->setEnabled(view_item->item()->isEnabled());
87 connect(
view_model.get(), &ViewModel::dataChanged, on_data_change);
90 connect(
view_model.get(), &ViewModel::rowsInserted, on_row_inserted);
93 connect(
view_model.get(), &ViewModel::rowsRemoved, on_row_removed);
100 auto view_item =
view_model->viewItemFromIndex(index);
101 if (
auto label_item =
dynamic_cast<ViewLabelItem*
>(view_item); label_item)
112 for (
int row = 0; row <
view_model->rowCount(); ++row) {
113 auto mapper = std::make_unique<QDataWidgetMapper>();
116 mapper->setRootIndex(QModelIndex());
117 mapper->setCurrentModelIndex(
view_model->index(row, 0));
130 for (
int row = 0; row <
view_model->rowCount(); ++row) {
131 for (
int col = 0; col <
view_model->columnCount(); ++col) {
135 widget_mappers[
static_cast<size_t>(row)]->addMapping(widget.get(), col);
136 grid_layout->addWidget(widget.release(), row, col);
145 auto main_layout =
new QVBoxLayout;
146 main_layout->setMargin(0);
147 main_layout->setSpacing(0);
149 p_impl->grid_layout->setSpacing(6);
150 main_layout->addLayout(
p_impl->grid_layout);
151 main_layout->addStretch(1);
153 setLayout(main_layout);
161 p_impl->view_model->setRootSessionItem(item);
163 p_impl->update_grid_layout();
void dataChanged(QVariant value)
Emmits signal when data was changed in an editor.
Default editor factory for cell editors in Qt trees and tables.
std::unique_ptr< PropertyFlatViewImpl > p_impl
void setItem(SessionItem *item)
PropertyFlatView(QWidget *parent=nullptr)
The main object representing an editable/displayable/serializable entity.
bool isEnabled() const
Returns true if this item has enabled flag set.
SessionModel * model() const
Returns the model to which given item belongs to.
Represents the view of SessionItem's data in a single cell of ViewModel.
virtual QVariant data(int qt_role) const
Returns the data for given role according to Qt::ItemDataRole namespace definitions.
SessionItem * item() const
Represents display name of SessionItem in any cell of Qt's trees and tables.
Model delegate to provide editing/painting for custom variants.
void onCustomEditorDataChanged()
void clearGridLayout(QGridLayout *layout, bool deleteWidgets=true)
Clear layout completely.
MVVM_VIEWMODEL_EXPORT std::unique_ptr< ViewModel > CreatePropertyFlatViewModel(SessionModel *model)
Creates view model to represent SessionModel for Qt views.
MVVM_VIEWMODEL_EXPORT QVariant TextColorRole(const SessionItem &item)
Returns text color for given item.
materialitems.h Collection of materials to populate MaterialModel.
QVariant ForegroundRole(const SessionItem &item)
Returns text color for given item.
std::unique_ptr< CustomEditor > create_editor(const QModelIndex &index)
Creates custom editor for given index.
std::unique_ptr< QLabel > create_label(ViewItem *view_item)
Creates label for given index.
std::map< ViewItem *, QWidget * > item_to_widget
std::unique_ptr< DefaultEditorFactory > editor_factory
QGridLayout * grid_layout
void update_grid_layout()
Updates grid layout with all editors corresponding to the model.
std::vector< std::unique_ptr< QDataWidgetMapper > > widget_mappers
std::unique_ptr< QWidget > create_widget(const QModelIndex &index)
Creates widget for given index to appear in grid layout.
std::unique_ptr< ViewModelDelegate > m_delegate
void update_mappers()
Creates row of widget mappers. Each widget mapper will serve all editors in a column.
std::unique_ptr< ViewModel > view_model
void connect_model()
Connect model.