Files
create/src/Mod/Material/Gui/ModelSelect.h
David Carter 00c57a9d08 Materials: External Modules Part 1
Refactored code to support local and external material sources

This is the first PR in a series to support external modules. External
modules allow materials to be stored in external data sources such as
databases or web services. No new functionality is introduced in this
PR, rather it is a refactoring of code that will allow for changes to
be introduced in future PRs. Minor performance improvements have also
been made in the model and material managers.

The Python API has been enhanced for many data types to allow for
modification within Python.
2025-03-18 20:33:10 -05:00

106 lines
3.8 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_MODELSELECT_H
#define MATGUI_MODELSELECT_H
#include <memory>
#include <QDialog>
#include <QDir>
#include <QStandardItem>
#include <QTableView>
#include <QTreeView>
#include <Mod/Material/App/Materials.h>
#include <Mod/Material/App/Model.h>
#include <Mod/Material/App/ModelManager.h>
namespace MatGui
{
class Ui_ModelSelect;
class ModelSelect: public QDialog
{
Q_OBJECT
public:
explicit ModelSelect(QWidget* parent = nullptr,
Materials::ModelFilter filter = Materials::ModelFilter_None);
~ModelSelect() override;
void onURL(bool checked);
void onDOI(bool checked);
void onFavourite(bool checked);
void onSelectModel(const QItemSelection& selected, const QItemSelection& deselected);
void onDoubleClick(const QModelIndex& index);
const QString& selectedModel() const
{
return _selected;
}
void accept() override;
void reject() override;
private:
void getFavorites();
void saveFavorites();
void addFavorite(const QString& uuid);
void removeFavorite(const QString& uuid);
bool isFavorite(const QString& uuid) const;
void getRecents();
void saveRecents();
void addRecent(const QString& uuid);
bool isRecent(const QString& uuid) const;
void addExpanded(QTreeView* tree, QStandardItem* parent, QStandardItem* child);
void addExpanded(QTreeView* tree, QStandardItemModel* parent, QStandardItem* child);
void addRecents(QStandardItem* parent);
void addFavorites(QStandardItem* parent);
void
addModels(QStandardItem& parent,
const std::shared_ptr<std::map<QString, std::shared_ptr<Materials::ModelTreeNode>>>
modelTree,
const QIcon& icon);
void updateMaterialModel(const QString& uuid);
void clearMaterialModel();
void createModelTree();
void refreshModelTree();
void fillTree();
void setHeaders(QStandardItemModel* model);
void setColumnWidths(QTableView* table);
void updateModelProperties(std::shared_ptr<Materials::Model> model);
void createModelProperties();
Materials::ModelFilter _filter;
std::unique_ptr<Ui_ModelSelect> ui;
QString _selected;
std::list<QString> _favorites;
std::list<QString> _recents;
int _recentMax;
};
} // namespace MatGui
#endif // MATGUI_MODELSELECT_H