File indexing completed on 2024-05-19 05:42:28

0001 // ct_lvtqtw_tabwidget.h                                             -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #ifndef INCLUDED_LVTQTW_TABWIDGET
0021 #define INCLUDED_LVTQTW_TABWIDGET
0022 
0023 #include <lvtqtw_export.h>
0024 
0025 #include <ct_lvtldr_lakosiannode.h>
0026 #include <ct_lvtmdl_modelhelpers.h>
0027 #include <ct_lvtplg_pluginmanager.h>
0028 
0029 #include <ct_lvtprj_projectfile.h>
0030 #include <ct_lvtshr_graphenums.h>
0031 
0032 #include <QTabWidget>
0033 
0034 #include <memory>
0035 #include <optional>
0036 #include <string>
0037 
0038 class QGraphicsView;
0039 class QString;
0040 
0041 namespace Codethink::lvtldr {
0042 class NodeStorage;
0043 }
0044 namespace Codethink::lvtclr {
0045 class ColorManagement;
0046 }
0047 namespace Codethink::lvtqtc {
0048 class GraphicsView;
0049 class UndoManager;
0050 } // namespace Codethink::lvtqtc
0051 namespace Codethink::lvtprj {
0052 class ProjectFile;
0053 }
0054 
0055 namespace Codethink::lvtqtw {
0056 
0057 class GraphTabElement;
0058 
0059 class LVTQTW_EXPORT TabWidget : public QTabWidget
0060 // Visualizes a Tree model and reacts to changes
0061 {
0062     Q_OBJECT
0063   public:
0064     // CREATORS
0065     TabWidget(Codethink::lvtldr::NodeStorage& nodeStorage,
0066               lvtprj::ProjectFile& projectFile,
0067               std::shared_ptr<lvtclr::ColorManagement> colorManagement,
0068               lvtplg::PluginManager *pluginManager = nullptr,
0069               QWidget *parent = nullptr);
0070     // Constructor
0071 
0072     ~TabWidget() noexcept override;
0073     // Destructor
0074 
0075     /* Opens a new tab and loads qualifiedName if it exist */
0076     void openNewGraphTab(std::optional<QSet<QString>> qualifiedNames = std::nullopt);
0077 
0078     /* Clears the current graph and loads the qualifiedName */
0079     void replaceGraphAt(int idx, const QString& qualifiedName);
0080 
0081     void closeTab(int idx);
0082 
0083     void setCurrentTabText(const QString& fullyQualifiedName);
0084     // Slot for when we need to update the tab name to keep up with a history
0085     // change
0086 
0087     lvtqtc::GraphicsView *graphicsView();
0088 
0089     void setUndoManager(lvtqtc::UndoManager *undoManager);
0090 
0091     Q_SIGNAL void currentTabTextChanged(const QString& name);
0092     Q_SIGNAL void errorMessage(const QString& errorMessage);
0093     // triggered when we set the text of the current tab.
0094 
0095     void saveBookmarkByTabIndex(int tabIdx);
0096     void saveBookmark(const QString& name, int idx, Codethink::lvtprj::ProjectFile::BookmarkType type);
0097     void loadBookmark(const QJsonDocument& doc, lvtshr::HistoryType historyType);
0098 
0099     // Called when the application closes or when the user clicks on save.
0100     void saveTabsOnProject(Codethink::lvtprj::ProjectFile::BookmarkType type);
0101 
0102   private:
0103     // Forbid using addTab and insertTab, this should work with Graphs Only.
0104     using QTabWidget::addTab;
0105     using QTabWidget::insertTab;
0106 
0107     GraphTabElement *createTabElement();
0108 
0109     // DATA
0110     // TYPES
0111     struct Private;
0112     std::unique_ptr<Private> d;
0113 };
0114 
0115 } // end namespace Codethink::lvtqtw
0116 
0117 #endif