Material: Material editor enhancements
Continues the work of the material subsystem improvements. This merge covers the continued development of the material editor. The primary improvements are the addition of new data types, a new appearance preview UI, and changes in the array data types. New data types were added to support more advanced workflows, such as the Render Workbench.The Image datatype allows the material to embed the image in the card instead of pointing to an image in an external file. Multi-buyte strings span multiple lines as the name implies. It preserves formatting accross those lines. Also several list types are now supported, with the primary difference being the editors. List is a list of strings, FileList is a list of file path names, and ImageList is a list of embedded images. For the appearance preview, the UI now uses the same Coin library as is used in the documents, meaning the preview will look exactly the same as the material will be shown in the documents. The array data types are now more complete. The default value wasn't being used as originially envisioned and was tehrefore removed. For 3D arrays, the Python API was implemented. There were a lot of code clean ups. This involved removing logging statements used for debugging during development, reduction of lint warnings, and code refactoring. The editor can automatically convert from previous format files to the current format. This has been extended to material files generated by the Render WB. Old format files are displayed in the editor with a warning icon. Selecting one will require saving the file in the new format before it can be used.
This commit is contained in:
committed by
Chris Hennes
parent
703561f7bc
commit
3dd6a67804
@@ -57,7 +57,7 @@
|
||||
using namespace MatGui;
|
||||
|
||||
ArrayDelegate::ArrayDelegate(Materials::MaterialValue::ValueType type,
|
||||
QString units,
|
||||
const QString& units,
|
||||
QObject* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
, _type(type)
|
||||
@@ -70,8 +70,7 @@ void ArrayDelegate::paint(QPainter* painter,
|
||||
{
|
||||
|
||||
if (_type == Materials::MaterialValue::Quantity) {
|
||||
const AbstractArrayModel* tableModel =
|
||||
reinterpret_cast<const AbstractArrayModel*>(index.model());
|
||||
auto* tableModel = dynamic_cast<const AbstractArrayModel*>(index.model());
|
||||
painter->save();
|
||||
|
||||
if (tableModel->newRow(index)) {
|
||||
@@ -79,7 +78,7 @@ void ArrayDelegate::paint(QPainter* painter,
|
||||
}
|
||||
else {
|
||||
QVariant item = tableModel->data(index);
|
||||
Base::Quantity quantity = item.value<Base::Quantity>();
|
||||
auto quantity = item.value<Base::Quantity>();
|
||||
QString text = quantity.getUserString();
|
||||
painter->drawText(option.rect, 0, text);
|
||||
}
|
||||
@@ -93,15 +92,11 @@ void ArrayDelegate::paint(QPainter* painter,
|
||||
|
||||
void ArrayDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||
{
|
||||
Base::Console().Log("ArrayDelegate::setEditorData()\n");
|
||||
|
||||
if (_type == Materials::MaterialValue::Quantity) {
|
||||
QAbstractItemModel* tableModel = const_cast<QAbstractItemModel*>(index.model());
|
||||
auto tableModel = dynamic_cast<const QAbstractItemModel*>(index.model());
|
||||
auto item = tableModel->data(index);
|
||||
|
||||
// Gui::InputField* input = static_cast<Gui::InputField*>(editor);
|
||||
// input->setText(item.toString());
|
||||
Gui::QuantitySpinBox* input = static_cast<Gui::QuantitySpinBox*>(editor);
|
||||
auto input = static_cast<Gui::QuantitySpinBox*>(editor);
|
||||
input->setValue(item.value<Base::Quantity>());
|
||||
}
|
||||
else {
|
||||
@@ -110,12 +105,12 @@ void ArrayDelegate::setEditorData(QWidget* editor, const QModelIndex& index) con
|
||||
}
|
||||
|
||||
QWidget* ArrayDelegate::createEditor(QWidget* parent,
|
||||
const QStyleOptionViewItem&,
|
||||
const QStyleOptionViewItem& styleOption,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
Base::Console().Log("ArrayDelegate::createEditor()\n");
|
||||
Q_UNUSED(styleOption)
|
||||
|
||||
const QAbstractTableModel* tableModel = static_cast<const QAbstractTableModel*>(index.model());
|
||||
auto tableModel = dynamic_cast<const QAbstractTableModel*>(index.model());
|
||||
auto item = tableModel->data(index);
|
||||
|
||||
QWidget* editor = createWidget(parent, item);
|
||||
@@ -139,7 +134,7 @@ QWidget* ArrayDelegate::createWidget(QWidget* parent, const QVariant& item) cons
|
||||
widget = spinner;
|
||||
}
|
||||
else if (_type == Materials::MaterialValue::Float) {
|
||||
Gui::DoubleSpinBox* spinner = new Gui::DoubleSpinBox(parent);
|
||||
auto spinner = new Gui::DoubleSpinBox(parent);
|
||||
|
||||
// the magnetic permeability is the parameter for which many decimals matter
|
||||
// the most however, even for this, 6 digits are sufficient
|
||||
@@ -154,7 +149,7 @@ QWidget* ArrayDelegate::createWidget(QWidget* parent, const QVariant& item) cons
|
||||
widget = spinner;
|
||||
}
|
||||
else if (_type == Materials::MaterialValue::Boolean) {
|
||||
Gui::PrefComboBox* combo = new Gui::PrefComboBox(parent);
|
||||
auto combo = new Gui::PrefComboBox(parent);
|
||||
combo->insertItem(0, QString::fromStdString(""));
|
||||
combo->insertItem(1, tr("False"));
|
||||
combo->insertItem(2, tr("True"));
|
||||
@@ -162,7 +157,7 @@ QWidget* ArrayDelegate::createWidget(QWidget* parent, const QVariant& item) cons
|
||||
widget = combo;
|
||||
}
|
||||
else if (_type == Materials::MaterialValue::Quantity) {
|
||||
Gui::QuantitySpinBox* input = new Gui::QuantitySpinBox();
|
||||
auto input = new Gui::QuantitySpinBox();
|
||||
input->setMinimum(std::numeric_limits<double>::min());
|
||||
input->setMaximum(std::numeric_limits<double>::max());
|
||||
input->setUnitText(_units);
|
||||
@@ -170,6 +165,15 @@ QWidget* ArrayDelegate::createWidget(QWidget* parent, const QVariant& item) cons
|
||||
|
||||
widget = input;
|
||||
}
|
||||
else if (_type == Materials::MaterialValue::FileList) {
|
||||
auto chooser = new Gui::FileChooser();
|
||||
auto propertyValue = item.toString();
|
||||
if (!propertyValue.isEmpty()) {
|
||||
chooser->setFileName(propertyValue);
|
||||
}
|
||||
|
||||
widget = chooser;
|
||||
}
|
||||
else {
|
||||
// Default editor
|
||||
widget = new QLineEdit(parent);
|
||||
@@ -179,5 +183,3 @@ QWidget* ArrayDelegate::createWidget(QWidget* parent, const QVariant& item) cons
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
#include "moc_ArrayDelegate.cpp"
|
||||
|
||||
Reference in New Issue
Block a user