mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-14 17:44:13 +02:00
ecc7a39131
The zipped project (.qetz) is the format QElectroTech saves.
- Save As and the first Save of a new project offer .qetz first
("untitled.qetz"); .qet can still be chosen.
- A project read from a .qet is saved as a .qetz beside it, the .qet left
as it is (QETProject::write(), so Save, autosave, a script's save and the
assistant's live save all do it). The project then works on the .qetz.
A path chosen afterwards (Save As, a script naming one) is saved to as it
is. The editor says so before the first such save, and asks before
replacing a .qetz already there.
- File > Save a copy for an older QElectroTech writes a .qet copy, for a
version that cannot open a .qetz; the project keeps its own file.
- The operating systems know the file: a freedesktop MIME type
application/x-qelectrotech-project+zip (*.qetz, and by its mimetype
entry when the name says nothing), the desktop file, macOS's document
types and the Windows installer's association.
Crash backups stay XML, written beside the project as before.
tst_resaveunchanged::qetSavedAsQetzBeside: a .qet saved where it is leaves
the .qet byte for byte and writes a .qetz beside it holding what a plain
save of the .qet holds; it fails when the switch is off. In a real window:
Ctrl+S on perceuse.qet shows the notice, writes perceuse.qetz and leaves
perceuse.qet's md5 unchanged; the copy for an older version (reached by
command search) equals a plain save but for time_spent; a new project's
Save offers untitled.qetz. xdg-mime finds the type by name and by content.
ctest 96/96 with and without QET_LAZY_FOLIOS=1; srclint R-C clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
200 lines
5.2 KiB
C++
200 lines
5.2 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech 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 General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef PROJECT_VIEW_H
|
|
#define PROJECT_VIEW_H
|
|
|
|
#include "qetresult.h"
|
|
#include "titleblock/templatelocation.h"
|
|
|
|
#include <QCloseEvent>
|
|
#include <QTabBar>
|
|
#include <QWidget>
|
|
#include <QtWidgets>
|
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
class WheelEnabledTabBar : public QTabWidget
|
|
{
|
|
public:
|
|
WheelEnabledTabBar(QWidget *parent = nullptr)
|
|
: QTabWidget(parent)
|
|
{}
|
|
|
|
void wheelEvent(QWheelEvent *event) override
|
|
{
|
|
// Only intercept if Ctrl is held down
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
int index = currentIndex();
|
|
if (index != -1) {
|
|
// angleDelta().y() is usually 120 per click.
|
|
// Dividing by 120 gives you exactly +1 (scroll up) or -1 (scroll down)
|
|
int steps = event->angleDelta().y() / 120;
|
|
|
|
if (steps != 0) {
|
|
int newIndex = index - steps;
|
|
|
|
if (newIndex >= 0 && newIndex < count())
|
|
setCurrentIndex(newIndex);
|
|
}
|
|
}
|
|
event->accept(); // Mark event handled so parent widgets don't process it
|
|
} else {
|
|
// Allow the default QTabWidget wheel behavior to process if Ctrl isn't held
|
|
QTabWidget::wheelEvent(event);
|
|
}
|
|
}
|
|
};
|
|
#endif
|
|
|
|
|
|
class QETProject;
|
|
class DiagramView;
|
|
class Diagram;
|
|
class ElementsLocation;
|
|
class QTabWidget;
|
|
class QLabel;
|
|
class QVBoxLayout;
|
|
|
|
|
|
/**
|
|
@brief The ProjectView class
|
|
This class provides a widget displaying the diagrams of a particular
|
|
project using tabs.
|
|
*/
|
|
class ProjectView : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
// constructors, destructor
|
|
public:
|
|
ProjectView(QETProject *, QWidget * = nullptr);
|
|
~ProjectView() override;
|
|
private:
|
|
ProjectView(const ProjectView &);
|
|
|
|
//Method related to construction of this class
|
|
void setProject(QETProject *project);
|
|
|
|
|
|
|
|
// methods
|
|
public:
|
|
QETProject *project();
|
|
QList<DiagramView *> diagram_views() const;
|
|
DiagramView *currentDiagram() const;
|
|
void closeEvent(QCloseEvent *) override;
|
|
void changeTabUp();
|
|
void changeTabDown();
|
|
void changeFirstTab();
|
|
void changeLastTab();
|
|
void setDiagramPosition(Diagram *diagram, int new_position);
|
|
|
|
public slots:
|
|
void removeDiagram(DiagramView *diagram_view, bool silent = false);
|
|
void removeDiagram(Diagram *diagram, bool silent = false);
|
|
void showDiagram(DiagramView *);
|
|
void showDiagram(Diagram *);
|
|
void editProjectProperties();
|
|
void editCurrentDiagramProperties();
|
|
void editDiagramProperties(DiagramView *);
|
|
void editDiagramProperties(Diagram *);
|
|
void moveDiagramUp(DiagramView *);
|
|
void moveDiagramUp(Diagram *);
|
|
void moveDiagramDown(DiagramView *);
|
|
void moveDiagramDown(Diagram *);
|
|
void moveDiagramUpTop(DiagramView *);
|
|
void moveDiagramUpTop(Diagram *);
|
|
void moveDiagramUpx10(DiagramView *);
|
|
void moveDiagramUpx10(Diagram *);
|
|
void moveDiagramDownx10(DiagramView *);
|
|
void moveDiagramDownx10(Diagram *);
|
|
void moveDiagramUpx100(DiagramView *);
|
|
void moveDiagramUpx100(Diagram *);
|
|
void moveDiagramDownx100(DiagramView *);
|
|
void moveDiagramDownx100(Diagram *);
|
|
void exportProject();
|
|
QETResult save();
|
|
QETResult saveAs();
|
|
QETResult doSave();
|
|
QETResult saveCopyForOlderVersions();
|
|
int cleanProject();
|
|
void updateWindowTitle();
|
|
void updateTabTitle(DiagramView *);
|
|
void updateAllTabsTitle();
|
|
void tabMoved(int, int);
|
|
|
|
signals:
|
|
void diagramAdded(DiagramView *);
|
|
void diagramRemoved(DiagramView *);
|
|
void diagramActivated(DiagramView *);
|
|
void projectClosed(ProjectView *);
|
|
void errorEncountered(const QString &);
|
|
// relayed signals
|
|
void findElementRequired(const ElementsLocation &);
|
|
|
|
private:
|
|
void initActions();
|
|
void initWidgets();
|
|
void initLayout();
|
|
void loadDiagrams();
|
|
DiagramView *findDiagram(Diagram *);
|
|
DiagramView *nextDiagram();
|
|
DiagramView *previousDiagram();
|
|
DiagramView *firstDiagram();
|
|
DiagramView *lastDiagram();
|
|
void rebuildDiagramsMap();
|
|
bool tryClosing();
|
|
bool tryClosingElementEditors();
|
|
int tryClosingDiagrams();
|
|
QString askUserForFilePath(bool = true);
|
|
QETResult noProjectResult() const;
|
|
|
|
private slots:
|
|
void tabChanged(int);
|
|
void tabDoubleClicked(int);
|
|
void setDisplayFallbackWidget(bool);
|
|
void adjustReadOnlyState();
|
|
void diagramAdded(Diagram *diagram);
|
|
void diagramRemoved(Diagram *diagram);
|
|
|
|
// attributes
|
|
private:
|
|
QAction *m_add_new_diagram,
|
|
*m_first_view,
|
|
*m_end_view,
|
|
*m_next_view_left,
|
|
*m_next_view_right;
|
|
QETProject *m_project;
|
|
QVBoxLayout *layout_;
|
|
QWidget *fallback_widget_;
|
|
QLabel *fallback_label_;
|
|
|
|
#ifdef Q_OS_MACOS
|
|
WheelEnabledTabBar *m_tab;
|
|
#else
|
|
QTabWidget *m_tab;
|
|
#endif
|
|
|
|
QMap<int, DiagramView *> m_diagram_ids;
|
|
int m_previous_tab_index = -1;
|
|
QList<DiagramView *> m_diagram_view_list;
|
|
};
|
|
|
|
|
|
#endif
|