mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 10:34:14 +02:00
Add a local, per-project time-spent tracker (#576)
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>
This commit is contained in:
@@ -996,6 +996,9 @@ QDomDocument QETProject::toXml()
|
||||
writeProjectPropertiesXml(project_properties);
|
||||
project_root.appendChild(project_properties);
|
||||
|
||||
// local, non-transmitted usage tracking (time spent on this project)
|
||||
writeUsageXml(project_root);
|
||||
|
||||
// Properties for news diagrams
|
||||
QDomElement new_diagrams_properties = xml_doc.createElement("newdiagrams");
|
||||
writeDefaultPropertiesXml(new_diagrams_properties);
|
||||
@@ -1496,6 +1499,9 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
|
||||
//Load the project-wide properties
|
||||
readProjectPropertiesXml(xml_project);
|
||||
|
||||
//Load the local, non-transmitted usage tracking
|
||||
readUsageXml(xml_project);
|
||||
|
||||
//Load the default properties for the new diagrams
|
||||
readDefaultPropertiesXml(xml_project);
|
||||
|
||||
@@ -1649,6 +1655,17 @@ void QETProject::readProjectPropertiesXml(QDomDocument &xml_project)
|
||||
m_project_properties.fromXml(dom_elmt);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::readUsageXml
|
||||
Load the local, non-transmitted usage tracking (time spent on this
|
||||
project) from the XML description of the project.
|
||||
@param xml_project : the xml description of the project
|
||||
*/
|
||||
void QETProject::readUsageXml(QDomDocument &xml_project)
|
||||
{
|
||||
m_project_properties_handler.usageTracker().fromXml(xml_project.documentElement());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::readDefaultPropertiesXml
|
||||
load default properties for new diagram, found in the xml of this project
|
||||
@@ -1784,6 +1801,15 @@ void QETProject::writeProjectPropertiesXml(QDomElement &xml_element) {
|
||||
m_project_properties.toXml(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::writeUsageXml
|
||||
Export the local, non-transmitted usage tracking (time spent on this
|
||||
project) as a <usage> child of \a xml_element.
|
||||
*/
|
||||
void QETProject::writeUsageXml(QDomElement &xml_element) {
|
||||
m_project_properties_handler.usageTracker().toXml(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::writeDefaultPropertiesXml
|
||||
Export all defaults properties used by a new diagram and his content
|
||||
|
||||
Reference in New Issue
Block a user