mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 18:44:13 +02:00
464d516537
Adds a ProjectUsageTracker (sources/project/) that accumulates how
long a project has been the active tab, using QElapsedTimer so the
value is computed on demand rather than via polling. It's hosted on
ProjectPropertiesHandler per that class's own stated design intent
("all new properties should be managed by this class").
The accumulated time is persisted as a new <usage time_spent="N"
enabled="true|false"/> element, a sibling of <properties> in the
project XML, written/read by new QETProject::writeUsageXml()/
readUsageXml(). It rides along on the existing autosave path for
free, since writeBackup() already serializes the full project via
toXml().
QETDiagramEditor::subWindowActivated() now pauses every open
project's tracker except the one whose tab just became current, so
switching between several open projects keeps each project's tracked
time isolated.
Surfaced in the existing Project Properties "Général" page: a
"Temps passé sur ce projet" display, a "Réinitialiser" button, and
an opt-out checkbox ("uniquement enregistré localement dans ce
fichier" - this is local-only, never transmitted anywhere).
Verified beyond compiling: full CMake build, then an actual runtime
session confirming the saved XML's time_spent value, that closing
and reopening the project round-trips and resumes timing, that the
reset button works, and - the key correctness check - that with two
projects open, the inactive one's time_spent stays frozen while the
active one accumulates real elapsed time, over the same interval.
See discussion #576.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
59 lines
1.7 KiB
C++
59 lines
1.7 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 PROJECTUSAGETRACKER_H
|
|
#define PROJECTUSAGETRACKER_H
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
class QDomElement;
|
|
|
|
/**
|
|
@brief The ProjectUsageTracker class
|
|
Accumulates how long a project has been the active tab, purely locally:
|
|
the value lives only in the project's own file (a <usage> element next
|
|
to <properties>) and is never transmitted anywhere.
|
|
|
|
The owning code (QETDiagramEditor) is expected to call setActive(true)
|
|
when this project's tab becomes the current one, and setActive(false)
|
|
when it stops being current (tab switch, project closed, ...).
|
|
*/
|
|
class ProjectUsageTracker
|
|
{
|
|
public:
|
|
ProjectUsageTracker() = default;
|
|
|
|
qint64 secondsSpent() const;
|
|
void resetSecondsSpent();
|
|
|
|
bool isEnabled() const {return m_enabled;}
|
|
void setEnabled(bool enabled);
|
|
|
|
void setActive(bool active);
|
|
|
|
void toXml(QDomElement &parent_element) const;
|
|
void fromXml(const QDomElement &parent_element);
|
|
|
|
private:
|
|
qint64 m_seconds_spent = 0;
|
|
bool m_enabled = true;
|
|
bool m_active = false;
|
|
QElapsedTimer m_elapsed_timer;
|
|
};
|
|
|
|
#endif // PROJECTUSAGETRACKER_H
|