Files
create/src/Mod/Material/Gui/MaterialSave.h
David Carter 817e7b1b4d 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.
2023-10-23 15:24:18 -04:00

105 lines
3.9 KiB
C++

/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef MATGUI_MATERIALSAVE_H
#define MATGUI_MATERIALSAVE_H
#include <memory>
#include <QAction>
#include <QDialog>
#include <QItemSelection>
#include <QStandardItem>
#include <QTreeView>
#include <Mod/Material/App/MaterialManager.h>
namespace MatGui
{
class Ui_MaterialSave;
class MaterialSave: public QDialog
{
Q_OBJECT
public:
MaterialSave(std::shared_ptr<Materials::Material> material, QWidget* parent = nullptr);
~MaterialSave() override;
void setLibraries();
void createModelTree();
void addExpanded(QTreeView* tree, QStandardItem* parent, QStandardItem* child);
void addExpanded(QTreeView* tree, QStandardItemModel* parent, QStandardItem* child);
void addMaterials(
QStandardItem& parent,
const std::shared_ptr<std::map<QString, std::shared_ptr<Materials::MaterialTreeNode>>>
modelTree,
const QIcon& folderIcon,
const QIcon& icon);
void showSelectedTree();
void onSelectModel(const QItemSelection& selected, const QItemSelection& deselected);
void currentTextChanged(const QString& value);
void onNewFolder(bool checked);
void onItemChanged(QStandardItem* item);
void onFilename(const QString& text);
void onContextMenu(const QPoint& pos);
void onDelete(bool checked);
void onInherited(int state);
void onOk(bool checked);
void onCancel(bool checked);
int confirmOverwrite(const QString& filename);
int confirmNewMaterial();
int confirmCopy();
void accept() override;
void reject() override;
private:
std::unique_ptr<Ui_MaterialSave> ui;
Materials::MaterialManager _manager;
std::shared_ptr<Materials::Material> _material;
bool _saveInherited;
QString _selectedPath;
QString _selectedFull;
QString _selectedUUID;
QString _libraryName;
QString _filename;
QAction _deleteAction;
QString getPath(const QStandardItem* item) const;
std::shared_ptr<Materials::MaterialLibrary> currentLibrary();
void createFolder(const QString& path);
void renameFolder(const QString& oldPath, const QString& newPath);
void deleteRecursive(const QString& path);
QString pathFromIndex(const QModelIndex& index) const;
int confirmDelete(QWidget* parent);
bool selectedHasChildren();
void deleteSelected();
void removeChildren(QStandardItem* item);
void removeSelectedFromTree();
};
} // namespace MatGui
#endif // MATGUI_MATERIALSAVE_H