37 #include <QStandardItemModel>
48 std::unique_ptr<CustomEditor>
createEditor(
const QVariant& variant,
50 const std::string& editor_type = {})
56 if (limits.hasLowerLimit() || limits.hasUpperLimit())
57 propertyItem->setLimits(limits);
58 if (!editor_type.empty())
59 propertyItem->setEditorType(editor_type);
63 return m_factory->createEditor(viewModel.index(0, 1));
76 auto editor = createEditor(QVariant::fromValue(
true));
77 EXPECT_TRUE(
dynamic_cast<BoolEditor*
>(editor.get()));
84 auto editor = createEditor(QVariant::fromValue(42));
87 auto spin_box = editor->findChild<QSpinBox*>();
89 ASSERT_TRUE(spin_box !=
nullptr);
90 EXPECT_EQ(spin_box->minimum(), -65536);
91 EXPECT_EQ(spin_box->maximum(), 65536);
101 auto spin_box = editor->findChild<QSpinBox*>();
102 ASSERT_TRUE(spin_box !=
nullptr);
103 EXPECT_EQ(spin_box->minimum(), -1);
104 EXPECT_EQ(spin_box->maximum(), 1);
111 auto editor = createEditor(QVariant::fromValue(42.42));
115 ASSERT_TRUE(spin_box !=
nullptr);
116 EXPECT_FLOAT_EQ(spin_box->minimum(), -std::numeric_limits<double>::max());
117 EXPECT_FLOAT_EQ(spin_box->maximum(), std::numeric_limits<double>::max());
128 ASSERT_TRUE(spin_box !=
nullptr);
129 EXPECT_FLOAT_EQ(spin_box->minimum(), 41);
130 EXPECT_FLOAT_EQ(spin_box->maximum(), 43);
137 auto editor = createEditor(QVariant::fromValue(QColor(Qt::green)));
138 EXPECT_TRUE(
dynamic_cast<ColorEditor*
>(editor.get()));
145 auto editor = createEditor(QVariant::fromValue(
ComboProperty()));
162 auto editor = createEditor(QVariant::fromValue(std::string(
"text")));
163 EXPECT_EQ(editor.get(),
nullptr);
167 EXPECT_EQ(editor.get(),
nullptr);
170 editor = createEditor(QVariant());
171 EXPECT_EQ(editor.get(),
nullptr);
174 EXPECT_EQ(m_factory->createEditor(QModelIndex()),
nullptr);
190 QStandardItemModel model;
191 auto parent = model.invisibleRootItem();
192 QList<QStandardItem*> children{
new QStandardItem};
193 parent->appendRow(children);
195 auto item = model.item(0, 0);
198 auto editor = m_factory->createEditor(model.index(0, 0));
~DefaultEditorFactoryTest()
std::unique_ptr< DefaultEditorFactory > m_factory
DefaultEditorFactoryTest()
std::unique_ptr< CustomEditor > createEditor(const QVariant &variant, RealLimits limits=RealLimits::limitless(), const std::string &editor_type={})
Helper function to build temporary model and create editor for cell.
Custom editor for QVariant based on bool values.
Custom editor for QVariant based on QColor.
Custom editor for QVariant based on ComboProperty.
Custom property to define list of string values with multiple selections.
Default editor factory for cell editors in Qt trees and tables.
View model to show content of SessionModel in Qt widgets: two column tree with label/data.
Custom editor for QVariant based on ExternalProperty.
Property to carry text, color and identifier.
Custom editor for QVariant based on integer with possibility to set limits.
Item to carry concrete editable entity (e.g.
static RealLimits limitless()
Creates an object withoud bounds (default)
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Custom editor for QVariant based on double with scientific notation support.
Adds multi-selection capabilities to QComboBox.
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
Main class to hold hierarchy of SessionItem objects.
bool setData(SessionItem *item, const Variant &value, int role)
Sets the data for given item.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
TEST_F(DefaultEditorFactoryTest, boolProperty)
Tests editor creation on bool property.
ExternalProperty colorProperty(const QColor &color)
Constructs color property from given color.
const std::string SelectableComboPropertyEditorType
materialitems.h Collection of materials to populate MaterialModel.