LibrePCB Developers Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
quickaccessmodel.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_EDITOR_QUICKACCESSMODEL_H
21#define LIBREPCB_EDITOR_QUICKACCESSMODEL_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "appwindow.h"
27
29
30#include <QtCore>
31
32/*******************************************************************************
33 * Namespace / Forward Declarations
34 ******************************************************************************/
35namespace librepcb {
36
37class Workspace;
38
39namespace editor {
40
41/*******************************************************************************
42 * Class QuickAccessModel
43 ******************************************************************************/
44
48class QuickAccessModel : public QObject,
49 public slint::Model<ui::TreeViewItemData> {
50 Q_OBJECT
51
52public:
53 // Constructors / Destructor
54 QuickAccessModel() = delete;
55 QuickAccessModel(const QuickAccessModel& other) = delete;
56 explicit QuickAccessModel(Workspace& ws, QObject* parent = nullptr) noexcept;
57 virtual ~QuickAccessModel() noexcept;
58
59 // General Methods
60 void pushRecentProject(const FilePath& fp) noexcept;
61 void discardRecentProject(const FilePath& fp) noexcept;
62 void setFavoriteProject(const FilePath& fp, bool favorite) noexcept;
63 bool isFavoriteProject(const FilePath& fp) const noexcept;
64
65 // Implementations
66 std::size_t row_count() const override;
67 std::optional<ui::TreeViewItemData> row_data(std::size_t i) const override;
68 void set_row_data(std::size_t i,
69 const ui::TreeViewItemData& data) noexcept override;
70
71 // Operator Overloadings
72 QuickAccessModel& operator=(const QuickAccessModel& rhs) = delete;
73
74signals:
75 void actionTriggered(const FilePath& fp, ui::Action a); // Internal signal.
76 void favoriteProjectChanged(const FilePath& fp, bool favorite);
77 void openFileTriggered(const FilePath& fp);
78
79private:
80 void load() noexcept;
81 void saveRecentProjects() noexcept;
82 void saveFavoriteProjects() noexcept;
83 void refreshItems() noexcept;
84 void setWatchedProjects(const QSet<FilePath>& projects) noexcept;
85 void handleAction(const FilePath& fp, ui::Action a) noexcept;
86
90 const slint::Image mIcon;
93 std::vector<ui::TreeViewItemData> mItems;
94 QFileSystemWatcher mWatcher;
96};
97
98/*******************************************************************************
99 * End of File
100 ******************************************************************************/
101
102} // namespace editor
103} // namespace librepcb
104
105#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The Workspace class represents a workspace with all its data (library, projects, settings,...
Definition workspace.h:54
The QuickAccessModel class.
Definition quickaccessmodel.h:49
QList< FilePath > mFavoriteProjects
Definition quickaccessmodel.h:92
bool isFavoriteProject(const FilePath &fp) const noexcept
Definition quickaccessmodel.cpp:113
void discardRecentProject(const FilePath &fp) noexcept
Definition quickaccessmodel.cpp:92
const slint::Image mIcon
Definition quickaccessmodel.h:90
const FilePath mFavoriteProjectsFp
Definition quickaccessmodel.h:89
std::optional< ui::TreeViewItemData > row_data(std::size_t i) const override
Definition quickaccessmodel.cpp:125
void openFileTriggered(const FilePath &fp)
void handleAction(const FilePath &fp, ui::Action a) noexcept
Definition quickaccessmodel.cpp:277
const Workspace & mWorkspace
Definition quickaccessmodel.h:87
QuickAccessModel(const QuickAccessModel &other)=delete
std::size_t row_count() const override
Definition quickaccessmodel.cpp:121
void saveRecentProjects() noexcept
Definition quickaccessmodel.cpp:176
QList< FilePath > mRecentProjects
Definition quickaccessmodel.h:91
void load() noexcept
Definition quickaccessmodel.cpp:146
void set_row_data(std::size_t i, const ui::TreeViewItemData &data) noexcept override
Definition quickaccessmodel.cpp:130
QFileSystemWatcher mWatcher
Definition quickaccessmodel.h:94
void favoriteProjectChanged(const FilePath &fp, bool favorite)
void setWatchedProjects(const QSet< FilePath > &projects) noexcept
Definition quickaccessmodel.cpp:255
const FilePath mRecentProjectsFp
Definition quickaccessmodel.h:88
void pushRecentProject(const FilePath &fp) noexcept
Definition quickaccessmodel.cpp:79
void setFavoriteProject(const FilePath &fp, bool favorite) noexcept
Definition quickaccessmodel.cpp:99
QTimer mWatcherTimer
Definition quickaccessmodel.h:95
void actionTriggered(const FilePath &fp, ui::Action a)
void saveFavoriteProjects() noexcept
Definition quickaccessmodel.cpp:191
std::vector< ui::TreeViewItemData > mItems
Definition quickaccessmodel.h:93
void refreshItems() noexcept
Definition quickaccessmodel.cpp:207
Definition occmodel.cpp:77
Definition uuid.h:186