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 in the handling of 2D and 3D array properties. These properties are now fully editable, and can be saved and restored. The cards now separate the author and license. These were previously saved as a single item. Future support will be provided for standard open source licenses. Saving operations validate the cards to ensure UUIDs of materials are considered. Warnings are given when a save could potentially impact the models, such as saving over a material instead of creating a new instance. The editor is still not complete. There are a number of functional elements, such as drag/drop operations, folder creation, and deletion operations that need to be added to the main tree. State needs to be saved and restored to improve the user experience. The appearance preview also needs significant work. This will be handled in a future PR.
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
#include <QMessageBox>
|
||||
#endif
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
#include <Gui/MainWindow.h>
|
||||
|
||||
#include <Mod/Material/App/Exceptions.h>
|
||||
@@ -39,32 +41,52 @@ using namespace MatGui;
|
||||
|
||||
/* TRANSLATOR MatGui::Array2D */
|
||||
|
||||
Array2D::Array2D(const QString& propertyName, Materials::Material* material, QWidget* parent)
|
||||
Array2D::Array2D(const QString& propertyName,
|
||||
std::shared_ptr<Materials::Material> material,
|
||||
QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui_Array2D)
|
||||
, _material(material)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if (material->hasPhysicalProperty(propertyName)) {
|
||||
_property = &(material->getPhysicalProperty(propertyName));
|
||||
_property = material->getPhysicalProperty(propertyName);
|
||||
}
|
||||
else if (material->hasAppearanceProperty(propertyName)) {
|
||||
_property = &(material->getAppearanceProperty(propertyName));
|
||||
_property = material->getAppearanceProperty(propertyName);
|
||||
}
|
||||
else {
|
||||
Base::Console().Log("Property '%s' not found\n", propertyName.toStdString().c_str());
|
||||
_property = nullptr;
|
||||
}
|
||||
if (_property) {
|
||||
Base::Console().Log("Value type %d\n",
|
||||
static_cast<int>(_property->getMaterialValue()->getType()));
|
||||
_value =
|
||||
std::static_pointer_cast<Materials::Material2DArray>(_property->getMaterialValue());
|
||||
}
|
||||
else {
|
||||
Base::Console().Log("No value loaded\n");
|
||||
_value = nullptr;
|
||||
}
|
||||
if (_value) {
|
||||
Base::Console().Log("Value type %d\n", static_cast<int>(_value->getType()));
|
||||
// auto value = _property->getMaterialValue()->getValue();
|
||||
// Base::Console().Log("\tQVariant type %d\n", value.userType());
|
||||
}
|
||||
|
||||
setupDefault();
|
||||
setupArray();
|
||||
|
||||
ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->tableView, &QWidget::customContextMenuRequested, this, &Array2D::onContextMenu);
|
||||
|
||||
_deleteAction.setText(tr("Delete row"));
|
||||
_deleteAction.setShortcut(Qt::Key_Delete);
|
||||
connect(&_deleteAction, &QAction::triggered, this, &Array2D::onDelete);
|
||||
ui->tableView->addAction(&_deleteAction);
|
||||
|
||||
connect(ui->standardButtons, &QDialogButtonBox::accepted, this, &Array2D::accept);
|
||||
connect(ui->standardButtons, &QDialogButtonBox::rejected, this, &Array2D::reject);
|
||||
}
|
||||
@@ -77,13 +99,16 @@ void Array2D::setupDefault()
|
||||
|
||||
try {
|
||||
const Materials::MaterialProperty& column1 = _property->getColumn(0);
|
||||
QString label = QString::fromStdString("Default ") + column1.getName();
|
||||
QString label = tr("Default ") + column1.getName();
|
||||
ui->labelDefault->setText(label);
|
||||
if (column1.getPropertyType() == QString::fromStdString("Quantity")) {
|
||||
ui->editDefault->setMinimum(std::numeric_limits<double>::min());
|
||||
ui->editDefault->setMaximum(std::numeric_limits<double>::max());
|
||||
ui->editDefault->setUnitText(_property->getColumnUnits(0));
|
||||
ui->editDefault->setValue(_value->getDefault().getValue().value<Base::Quantity>());
|
||||
if (!_value->defaultSet()) {
|
||||
_value->setDefault(_property->getColumnNull(0).value<Base::Quantity>());
|
||||
}
|
||||
ui->editDefault->setValue(_value->getDefault().value<Base::Quantity>());
|
||||
|
||||
connect(ui->editDefault,
|
||||
qOverload<const Base::Quantity&>(&Gui::QuantitySpinBox::valueChanged),
|
||||
@@ -134,15 +159,99 @@ void Array2D::setupArray()
|
||||
auto table = ui->tableView;
|
||||
auto model = new Array2DModel(_property, _value, this);
|
||||
table->setModel(model);
|
||||
table->setEditTriggers(QAbstractItemView::AllEditTriggers);
|
||||
// table->setEditTriggers(QAbstractItemView::AllEditTriggers);
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
setColumnWidths(table);
|
||||
setColumnDelegates(table);
|
||||
connect(model, &QAbstractItemModel::dataChanged, this, &Array2D::onDataChanged);
|
||||
}
|
||||
|
||||
void Array2D::onDataChanged(const QModelIndex& topLeft,
|
||||
const QModelIndex& bottomRight,
|
||||
const QVector<int>& roles)
|
||||
{
|
||||
Q_UNUSED(topLeft)
|
||||
Q_UNUSED(bottomRight)
|
||||
Q_UNUSED(roles)
|
||||
|
||||
_material->setEditStateAlter();
|
||||
}
|
||||
|
||||
void Array2D::defaultValueChanged(const Base::Quantity& value)
|
||||
{
|
||||
_value->setDefault(QVariant::fromValue(value));
|
||||
_material->setEditStateAlter();
|
||||
}
|
||||
|
||||
void Array2D::onContextMenu(const QPoint& pos)
|
||||
{
|
||||
Base::Console().Log("Array2D::onContextMenu(%d,%d)\n", pos.x(), pos.y());
|
||||
QModelIndex index = ui->tableView->indexAt(pos);
|
||||
Base::Console().Log("\tindex at (%d,%d)\n", index.row(), index.column());
|
||||
|
||||
|
||||
QMenu contextMenu(tr("Context menu"), this);
|
||||
|
||||
contextMenu.addAction(&_deleteAction);
|
||||
|
||||
contextMenu.exec(ui->tableView->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
bool Array2D::newRow(const QModelIndex& index)
|
||||
{
|
||||
Array2DModel* model = static_cast<Array2DModel*>(ui->tableView->model());
|
||||
return model->newRow(index);
|
||||
}
|
||||
|
||||
void Array2D::onDelete(bool checked)
|
||||
{
|
||||
Q_UNUSED(checked)
|
||||
|
||||
Base::Console().Log("Array2D::onDelete()\n");
|
||||
QItemSelectionModel* selectionModel = ui->tableView->selectionModel();
|
||||
if (!selectionModel->hasSelection() || newRow(selectionModel->currentIndex())) {
|
||||
Base::Console().Log("\tNothing selected\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int res = confirmDelete();
|
||||
if (res == QMessageBox::Cancel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int Array2D::confirmDelete()
|
||||
{
|
||||
QMessageBox box(this);
|
||||
box.setIcon(QMessageBox::Question);
|
||||
box.setWindowTitle(QObject::tr("Confirm Delete"));
|
||||
|
||||
QString prompt = QObject::tr("Are you sure you want to delete the row?");
|
||||
box.setText(prompt);
|
||||
|
||||
box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||
box.setDefaultButton(QMessageBox::Cancel);
|
||||
box.setEscapeButton(QMessageBox::Cancel);
|
||||
|
||||
int res = QMessageBox::Cancel;
|
||||
box.adjustSize(); // Silence warnings from Qt on Windows
|
||||
switch (box.exec()) {
|
||||
case QMessageBox::Ok:
|
||||
deleteSelected();
|
||||
res = QMessageBox::Ok;
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void Array2D::deleteSelected()
|
||||
{
|
||||
Array2DModel* model = static_cast<Array2DModel*>(ui->tableView->model());
|
||||
QItemSelectionModel* selectionModel = ui->tableView->selectionModel();
|
||||
auto index = selectionModel->currentIndex();
|
||||
model->deleteRow(index);
|
||||
}
|
||||
|
||||
void Array2D::accept()
|
||||
|
||||
Reference in New Issue
Block a user