Start: Remove old WB and replace with new
This commit is contained in:
@@ -1,31 +1,35 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2010 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
# Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include <Base/PyObjectBase.h>
|
||||
|
||||
#include <3rdParty/GSL/include/gsl/pointers>
|
||||
|
||||
namespace Start
|
||||
{
|
||||
@@ -37,13 +41,12 @@ public:
|
||||
{
|
||||
initialize("This module is the Start module."); // register with Python
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
PyObject* initModule()
|
||||
{
|
||||
return Base::Interpreter().addModule(new Module);
|
||||
auto newModule = gsl::owner<Module*>(new Module);
|
||||
return Base::Interpreter().addModule(newModule); // Transfer ownership
|
||||
}
|
||||
|
||||
} // namespace Start
|
||||
|
||||
@@ -1,20 +1,45 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
# /****************************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
# * *
|
||||
# * 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/>. *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
include_directories(
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${OCC_INCLUDE_DIR}
|
||||
${ZLIB_INCLUDE_DIR}
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
${QtCore_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(Start_LIBS
|
||||
FreeCADApp
|
||||
)
|
||||
FreeCADApp
|
||||
)
|
||||
|
||||
SET(Start_SRCS
|
||||
AppStart.cpp
|
||||
PreCompiled.cpp
|
||||
PreCompiled.h
|
||||
StartConfiguration.h
|
||||
)
|
||||
AppStart.cpp
|
||||
DisplayedFilesModel.cpp
|
||||
DisplayedFilesModel.h
|
||||
ExamplesModel.cpp
|
||||
ExamplesModel.h
|
||||
PreCompiled.cpp
|
||||
PreCompiled.h
|
||||
RecentFilesModel.cpp
|
||||
RecentFilesModel.h)
|
||||
|
||||
add_library(Start SHARED ${Start_SRCS})
|
||||
target_link_libraries(Start ${Start_LIBS})
|
||||
|
||||
223
src/Mod/Start/App/DisplayedFilesModel.cpp
Normal file
223
src/Mod/Start/App/DisplayedFilesModel.cpp
Normal file
@@ -0,0 +1,223 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <QByteArray>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#endif
|
||||
|
||||
#include "DisplayedFilesModel.h"
|
||||
#include <App/Application.h>
|
||||
#include <App/ProjectFile.h>
|
||||
|
||||
using namespace Start;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
std::string humanReadableSize(unsigned int bytes)
|
||||
{
|
||||
static const std::vector<std::string> siPrefix {
|
||||
"b",
|
||||
"kb",
|
||||
"Mb",
|
||||
"Gb",
|
||||
"Tb",
|
||||
"Pb",
|
||||
"Eb" // I think it's safe to stop here (for the time being)...
|
||||
};
|
||||
size_t base = 0;
|
||||
double inUnits = bytes;
|
||||
constexpr double siFactor {1000.0};
|
||||
while (inUnits > siFactor && base < siPrefix.size() - 1) {
|
||||
++base;
|
||||
inUnits /= siFactor;
|
||||
}
|
||||
if (base == 0) {
|
||||
// Don't include a decimal point for bytes
|
||||
return fmt::format("{:.0f} {}", inUnits, siPrefix[base]);
|
||||
}
|
||||
// For all others, include one digit after the decimal place
|
||||
return fmt::format("{:.1f} {}", inUnits, siPrefix[base]);
|
||||
}
|
||||
|
||||
FileStats fileInfoFromFreeCADFile(const std::string& path)
|
||||
{
|
||||
App::ProjectFile proj(path);
|
||||
proj.loadDocument();
|
||||
auto metadata = proj.getMetadata();
|
||||
FileStats result;
|
||||
result.insert(std::make_pair(DisplayedFilesModelRoles::author, metadata.createdBy));
|
||||
result.insert(
|
||||
std::make_pair(DisplayedFilesModelRoles::modifiedTime, metadata.lastModifiedDate));
|
||||
result.insert(std::make_pair(DisplayedFilesModelRoles::creationTime, metadata.creationDate));
|
||||
result.insert(std::make_pair(DisplayedFilesModelRoles::company, metadata.company));
|
||||
result.insert(std::make_pair(DisplayedFilesModelRoles::license, metadata.license));
|
||||
result.insert(std::make_pair(DisplayedFilesModelRoles::description, metadata.comment));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Load the thumbnail image data (if any) that is stored in an FCStd file.
|
||||
/// \returns The image bytes, or an empty QByteArray (if no thumbnail was stored)
|
||||
QByteArray loadFCStdThumbnail(const std::string& pathToFCStdFile)
|
||||
{
|
||||
App::ProjectFile proj(pathToFCStdFile);
|
||||
if (proj.loadDocument()) {
|
||||
try {
|
||||
std::string thumbnailFile = proj.extractInputFile("thumbnails/Thumbnail.png");
|
||||
auto inputFile = QFile(QString::fromStdString(thumbnailFile));
|
||||
inputFile.open(QIODevice::OpenModeFlag::ReadOnly);
|
||||
return inputFile.readAll();
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
FileStats getFileInfo(const std::string& path)
|
||||
{
|
||||
FileStats result;
|
||||
Base::FileInfo file(path);
|
||||
if (file.hasExtension("FCStd")) {
|
||||
result = fileInfoFromFreeCADFile(path);
|
||||
}
|
||||
else {
|
||||
file.lastModified();
|
||||
}
|
||||
result.insert(std::make_pair(DisplayedFilesModelRoles::path, path));
|
||||
result.insert(std::make_pair(DisplayedFilesModelRoles::size, humanReadableSize(file.size())));
|
||||
result.insert(std::make_pair(DisplayedFilesModelRoles::baseName, file.fileName()));
|
||||
return result;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DisplayedFilesModel::DisplayedFilesModel(QObject* parent)
|
||||
: QAbstractListModel(parent)
|
||||
{}
|
||||
|
||||
|
||||
int DisplayedFilesModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return static_cast<int>(_fileInfoCache.size());
|
||||
}
|
||||
|
||||
QVariant DisplayedFilesModel::data(const QModelIndex& index, int roleAsInt) const
|
||||
{
|
||||
int row = index.row();
|
||||
if (row < 0 || row >= static_cast<int>(_fileInfoCache.size())) {
|
||||
return {};
|
||||
}
|
||||
auto mapEntry = _fileInfoCache.at(row);
|
||||
auto role = static_cast<DisplayedFilesModelRoles>(roleAsInt);
|
||||
switch (role) {
|
||||
case DisplayedFilesModelRoles::author: // NOLINT(bugprone-branch-clone)
|
||||
[[fallthrough]];
|
||||
case DisplayedFilesModelRoles::baseName:
|
||||
[[fallthrough]];
|
||||
case DisplayedFilesModelRoles::company:
|
||||
[[fallthrough]];
|
||||
case DisplayedFilesModelRoles::creationTime:
|
||||
[[fallthrough]];
|
||||
case DisplayedFilesModelRoles::description:
|
||||
[[fallthrough]];
|
||||
case DisplayedFilesModelRoles::license:
|
||||
[[fallthrough]];
|
||||
case DisplayedFilesModelRoles::modifiedTime:
|
||||
[[fallthrough]];
|
||||
case DisplayedFilesModelRoles::path:
|
||||
[[fallthrough]];
|
||||
case DisplayedFilesModelRoles::size:
|
||||
if (mapEntry.find(role) != mapEntry.end()) {
|
||||
return QString::fromStdString(mapEntry.at(role));
|
||||
}
|
||||
else {
|
||||
return {};
|
||||
}
|
||||
case DisplayedFilesModelRoles::image: {
|
||||
auto path = QString::fromStdString(mapEntry.at(DisplayedFilesModelRoles::path));
|
||||
if (_imageCache.contains(path)) {
|
||||
return _imageCache[path];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (roleAsInt) {
|
||||
case Qt::ItemDataRole::ToolTipRole:
|
||||
return QString::fromStdString(mapEntry.at(DisplayedFilesModelRoles::path));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool freecadCanOpen(const QString& extension)
|
||||
{
|
||||
auto importTypes = App::GetApplication().getImportTypes();
|
||||
return std::find(importTypes.begin(), importTypes.end(), extension.toStdString())
|
||||
!= importTypes.end();
|
||||
}
|
||||
|
||||
void DisplayedFilesModel::addFile(const QString& filePath)
|
||||
{
|
||||
QFileInfo qfi(filePath);
|
||||
if (!qfi.isReadable()) {
|
||||
return;
|
||||
}
|
||||
if (!freecadCanOpen(qfi.suffix())) {
|
||||
return;
|
||||
}
|
||||
_fileInfoCache.emplace_back(getFileInfo(filePath.toStdString()));
|
||||
if (qfi.completeSuffix() == QLatin1String("FCStd")) {
|
||||
auto thumbnail = loadFCStdThumbnail(filePath.toStdString());
|
||||
if (!thumbnail.isEmpty()) {
|
||||
_imageCache.insert(filePath, thumbnail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayedFilesModel::clear()
|
||||
{
|
||||
_fileInfoCache.clear();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> DisplayedFilesModel::roleNames() const
|
||||
{
|
||||
static QHash<int, QByteArray> nameMap {
|
||||
std::make_pair(int(DisplayedFilesModelRoles::author), "author"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::baseName), "baseName"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::company), "company"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::creationTime), "creationTime"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::description), "description"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::image), "image"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::license), "license"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::modifiedTime), "modifiedTime"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::path), "path"),
|
||||
std::make_pair(int(DisplayedFilesModelRoles::size), "size"),
|
||||
};
|
||||
return nameMap;
|
||||
}
|
||||
85
src/Mod/Start/App/DisplayedFilesModel.h
Normal file
85
src/Mod/Start/App/DisplayedFilesModel.h
Normal file
@@ -0,0 +1,85 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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 FREECAD_START_DISPLAYEDFILESMODEL_H
|
||||
#define FREECAD_START_DISPLAYEDFILESMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <Base/Parameter.h>
|
||||
#include <QtQml/QQmlTypeInfo>
|
||||
|
||||
#include "../StartGlobal.h"
|
||||
|
||||
namespace Start
|
||||
{
|
||||
|
||||
enum class DisplayedFilesModelRoles
|
||||
{
|
||||
baseName = Qt::UserRole + 1,
|
||||
image,
|
||||
size,
|
||||
author,
|
||||
creationTime,
|
||||
modifiedTime,
|
||||
description,
|
||||
company,
|
||||
license,
|
||||
path
|
||||
};
|
||||
|
||||
using FileStats = std::map<DisplayedFilesModelRoles, std::string>;
|
||||
|
||||
/// A model for displaying a list of files including a thumbnail or icon, plus various file
|
||||
/// statistics.
|
||||
class StartExport DisplayedFilesModel: public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DisplayedFilesModel(QObject* parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
void addFile(const QString& filePath);
|
||||
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
/// For communication with QML, define the text version of each role name defined in the
|
||||
/// DisplayedFilesModelRoles enumeration
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
/// Destroy and recreate the cache of info about the files. Should be connected to a signal
|
||||
/// indicating when some piece of information about the files has changed. Does NOT generate
|
||||
/// a new list of files, only re-caches the existing ones.
|
||||
void reCacheFileInfo();
|
||||
|
||||
private:
|
||||
std::vector<FileStats> _fileInfoCache;
|
||||
QMap<QString, QByteArray> _imageCache;
|
||||
};
|
||||
|
||||
} // namespace Start
|
||||
|
||||
#endif // FREECAD_START_DISPLAYEDFILESMODEL_H
|
||||
57
src/Mod/Start/App/ExamplesModel.cpp
Normal file
57
src/Mod/Start/App/ExamplesModel.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <QDir>
|
||||
#endif
|
||||
|
||||
#include "ExamplesModel.h"
|
||||
#include <App/Application.h>
|
||||
|
||||
using namespace Start;
|
||||
|
||||
FC_LOG_LEVEL_INIT(ExamplesModel)
|
||||
|
||||
ExamplesModel::ExamplesModel(QObject* parent)
|
||||
: DisplayedFilesModel(parent)
|
||||
{
|
||||
auto examplesPath = QDir(QString::fromStdString(App::Application::getResourceDir()));
|
||||
_examplesDirectory.setPath(examplesPath.filePath(QLatin1String("examples")));
|
||||
}
|
||||
|
||||
void ExamplesModel::loadExamples()
|
||||
{
|
||||
beginResetModel();
|
||||
clear();
|
||||
if (!_examplesDirectory.isReadable()) {
|
||||
Base::Console().Warning("Cannot read %s",
|
||||
_examplesDirectory.absolutePath().toStdString().c_str());
|
||||
}
|
||||
auto entries = _examplesDirectory.entryList(QDir::Filter::Files | QDir::Filter::Readable,
|
||||
QDir::SortFlag::Name);
|
||||
for (const auto& entry : entries) {
|
||||
addFile(_examplesDirectory.filePath(entry));
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
54
src/Mod/Start/App/ExamplesModel.h
Normal file
54
src/Mod/Start/App/ExamplesModel.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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 FREECAD_START_EXAMPLESMODEL_H
|
||||
#define FREECAD_START_EXAMPLESMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QDir>
|
||||
#include <Base/Parameter.h>
|
||||
#include <QtQml/QQmlTypeInfo>
|
||||
|
||||
#include "DisplayedFilesModel.h"
|
||||
#include "../StartGlobal.h"
|
||||
|
||||
namespace Start
|
||||
{
|
||||
|
||||
/// A model for displaying a list of files including a thumbnail or icon, plus various file
|
||||
/// statistics.
|
||||
class StartExport ExamplesModel: public DisplayedFilesModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ExamplesModel(QObject* parent = nullptr);
|
||||
|
||||
void loadExamples();
|
||||
|
||||
private:
|
||||
QDir _examplesDirectory;
|
||||
};
|
||||
|
||||
} // namespace Start
|
||||
|
||||
#endif // FREECAD_START_EXAMPLESMODEL_H
|
||||
@@ -1,23 +1,25 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2010 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
# Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
# Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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 START_PRECOMPILED_H
|
||||
@@ -25,4 +26,26 @@
|
||||
|
||||
#include <FCConfig.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 5208)
|
||||
#endif
|
||||
|
||||
#ifdef _PreComp_
|
||||
|
||||
// standard
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
// Qt (should never include GUI files, only QtCore)
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
#endif // _PreComp_
|
||||
#endif // START_PRECOMPILED_H
|
||||
|
||||
52
src/Mod/Start/App/RecentFilesModel.cpp
Normal file
52
src/Mod/Start/App/RecentFilesModel.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include "RecentFilesModel.h"
|
||||
#include <App/Application.h>
|
||||
#include <App/ProjectFile.h>
|
||||
|
||||
using namespace Start;
|
||||
|
||||
RecentFilesModel::RecentFilesModel(QObject* parent)
|
||||
: DisplayedFilesModel(parent)
|
||||
{
|
||||
_parameterGroup = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/RecentFiles");
|
||||
}
|
||||
|
||||
void RecentFilesModel::loadRecentFiles()
|
||||
{
|
||||
beginResetModel();
|
||||
clear();
|
||||
auto numRows {_parameterGroup->GetInt("RecentFiles", 0)};
|
||||
for (int i = 0; i < numRows; ++i) {
|
||||
auto entry = fmt::format("MRU{}", i);
|
||||
auto path = _parameterGroup->GetASCII(entry.c_str(), "");
|
||||
addFile(QString::fromStdString(path));
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
53
src/Mod/Start/App/RecentFilesModel.h
Normal file
53
src/Mod/Start/App/RecentFilesModel.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/****************************************************************************
|
||||
* *
|
||||
* Copyright (c) 2024 The FreeCAD Project Association AISBL *
|
||||
* *
|
||||
* 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 FREECAD_START_RECENTFILESMODEL_H
|
||||
#define FREECAD_START_RECENTFILESMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <Base/Parameter.h>
|
||||
#include <QtQml/QQmlTypeInfo>
|
||||
|
||||
#include "DisplayedFilesModel.h"
|
||||
#include "../StartGlobal.h"
|
||||
|
||||
namespace Start
|
||||
{
|
||||
|
||||
/// A model for displaying a list of files including a thumbnail or icon, plus various file
|
||||
/// statistics.
|
||||
class StartExport RecentFilesModel: public DisplayedFilesModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RecentFilesModel(QObject* parent = nullptr);
|
||||
|
||||
void loadRecentFiles();
|
||||
|
||||
private:
|
||||
Base::Reference<ParameterGrp> _parameterGroup;
|
||||
};
|
||||
|
||||
} // namespace Start
|
||||
|
||||
#endif // FREECAD_START_RECENTFILESMODEL_H
|
||||
@@ -1,38 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef START_CONFIGURATION_H
|
||||
#define START_CONFIGURATION_H
|
||||
|
||||
#include <FCConfig.h>
|
||||
|
||||
// Exporting of App classes
|
||||
#ifdef FC_OS_WIN32
|
||||
#define START_SHOW_SKETCHER
|
||||
#define START_USE_DRAFTING
|
||||
#else // for Linux
|
||||
#define START_USE_DRAFTING
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user