mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 18:44:13 +02:00
5275fb44fe
Implements the first pillar of #574: a "Shortcuts" preferences page letting users rebind, search and reset every keyboard shortcut in the app. What it does - New ShortcutManager singleton: every one of the ~95 setShortcut()/ setShortcuts() call sites across qet.cpp, qetmainwindow.cpp, elementspanelwidget.cpp, autonumberingdockwidget.cpp, richtexteditor.cpp, qetdiagrameditor.cpp, qettemplateeditor.cpp and qetelementeditor.cpp now calls registerAction(target, id, category, default_sequence) instead, which applies the user's saved override (or the default) and remembers the target for later editing. - New ShortcutsConfigPage, added to the existing "Configurer QElectroTech" dialog: a filterable table of every registered shortcut, grouped by category, each with a QKeySequenceEdit and a per-row reset button, plus a "reset all" button. Bindings are only persisted (via ShortcutManager::setSequence()) when the dialog is accepted. - Conflict detection: rows whose currently-edited sequence collides with another row are highlighted with a tooltip naming the conflicting action. - Overrides are stored under a "shortcuts/" QSettings group, one key per id, keyed to match the id (not persisted at all when equal to the hardcoded default), so a future QET version can safely raise a default for anyone who never customized it. Design notes - Targets are handled generically via QObject rather than QAction, since one call site (autonumberingdockwidget's "Configurer" button) is a QPushButton, not a QAction. Both declare an identical "shortcut" QKeySequence Q_PROPERTY, so registerAction() reads/writes it through the property system instead of needing a separate code path. - Several live targets can share one id at once -- QET allows multiple windows of the same kind (diagram editor, element editor...) open simultaneously, each constructing its own QAction with the same id. setSequence() updates every live target for that id in one call, so a rebind takes effect in all open windows immediately, without restart. - A shortcut's description is captured from its target's text() the first time that id is registered, then cached -- so the config page stays correct even after the owning window is closed. One consequence: a shortcut belonging to an on-demand window (element editor, title block editor, rich text editor) only appears in the list once that window has been opened at least once in the current session, since nothing has registered its id yet otherwise. Testing Full CMake build (qmake CONFIG+=no_kf5, Qt 5.15) compiles clean with zero errors and zero new warnings. Verified end-to-end in a real running session (Xvfb + xdotool): - The Shortcuts page appears in Configure QElectroTech with the right icon, lists every always-registered shortcut with correct category/action name/ current binding. - The filter box correctly narrows the list, and correctly returns nothing for an action whose owning window hasn't been constructed yet this session (confirming the on-demand-registration behavior above is working as designed, not silently broken). - Conflict detection correctly flagged a real pre-existing same-key overlap between "Supprimer" (delete selection, Del) and "Supprimer ce folio" (delete diagram from panel, Del) -- both highlighted with explanatory tooltips. - Rebound "Manuel en ligne" to Ctrl+Shift+M, clicked OK: persisted under [shortcuts] in QElectroTech.conf, and the Aide menu's entry showed the new binding immediately, no restart needed. - Reopened the dialog: the rebind was still shown. Clicked its per-row reset button, then OK: the settings key was removed entirely (not stored as "F1"), correctly falling back to the hardcoded default. Retrofitting the Tab/Shift+Tab, select-all (#585) and Ctrl+G jump-to-element (#586) shortcuts through this registry is left for a follow-up once those PRs land, to avoid re-merging still-open branches into this one. Developed with assistance from Claude (Anthropic).
342 lines
9.9 KiB
C++
342 lines
9.9 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/>.
|
|
*/
|
|
#include "autonumberingdockwidget.h"
|
|
|
|
#include "../../diagram.h"
|
|
#include "../../diagramview.h"
|
|
#include "../../qetapp.h"
|
|
#include "../../shortcutmanager.h"
|
|
#include "../../titleblockproperties.h"
|
|
#include "../../ui/projectpropertiesdialog.h"
|
|
#include "../numerotationcontext.h"
|
|
#include "ui_autonumberingdockwidget.h"
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::AutoNumberingDockWidget
|
|
Constructor
|
|
@param parent : parent widget
|
|
*/
|
|
AutoNumberingDockWidget::AutoNumberingDockWidget(QWidget *parent) :
|
|
QDockWidget(parent),
|
|
ui(new Ui::AutoNumberingDockWidget)
|
|
{
|
|
ui->setupUi(this);
|
|
this->setDisabled(true);
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::~AutoNumberingDockWidget
|
|
Destructor
|
|
*/
|
|
AutoNumberingDockWidget::~AutoNumberingDockWidget()
|
|
{
|
|
this->disconnect();
|
|
delete ui;
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::clear
|
|
Remove all combo box values
|
|
*/
|
|
void AutoNumberingDockWidget::clear()
|
|
{
|
|
ui->m_conductor_cb->clear();
|
|
ui->m_element_cb->clear();
|
|
ui->m_folio_cb->clear();
|
|
}
|
|
|
|
void AutoNumberingDockWidget::projectClosed()
|
|
{
|
|
m_project = nullptr;
|
|
m_project_view = nullptr;
|
|
clear();
|
|
this->setDisabled(true);
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::setProject
|
|
@param project: project to be setted
|
|
@param projectview: projectview to be setted
|
|
assign Project and ProjectView, connect all signals and setContext
|
|
*/
|
|
void AutoNumberingDockWidget::setProject(QETProject *project,
|
|
ProjectView *projectview)
|
|
{
|
|
//Disconnect previous project
|
|
if (m_project && m_project_view)
|
|
{
|
|
//Conductor Signals
|
|
disconnect(m_project, SIGNAL(conductorAutoNumChanged()),
|
|
this,SLOT(conductorAutoNumChanged()));
|
|
disconnect (m_project,SIGNAL(conductorAutoNumRemoved()),
|
|
this,SLOT(conductorAutoNumChanged()));
|
|
disconnect (m_project,SIGNAL(conductorAutoNumAdded()),
|
|
this,SLOT(conductorAutoNumChanged()));
|
|
disconnect(m_project_view,SIGNAL(diagramActivated(DiagramView*)),
|
|
this,SLOT(setConductorActive(DiagramView*)));
|
|
|
|
//Element Signals
|
|
disconnect (m_project,SIGNAL(elementAutoNumRemoved(QString)),
|
|
this,SLOT(elementAutoNumChanged()));
|
|
disconnect (m_project,SIGNAL(elementAutoNumAdded(QString)),
|
|
this,SLOT(elementAutoNumChanged()));
|
|
|
|
//Folio Signals
|
|
disconnect (m_project,SIGNAL(folioAutoNumRemoved()),
|
|
this,SLOT(folioAutoNumChanged()));
|
|
disconnect (m_project,SIGNAL(folioAutoNumAdded()),
|
|
this,SLOT(folioAutoNumChanged()));
|
|
disconnect (this,
|
|
SIGNAL(folioAutoNumChanged(QString)),
|
|
&m_project_view->currentDiagram()->diagram()->border_and_titleblock,
|
|
SLOT (slot_setAutoPageNum(QString)));
|
|
disconnect(m_project, SIGNAL(defaultTitleBlockPropertiesChanged()),
|
|
this,SLOT(setActive()));
|
|
|
|
//Conductor, Element and Folio Signals
|
|
disconnect(m_project, &QETProject::destroyed,
|
|
this, &AutoNumberingDockWidget::projectClosed);
|
|
}
|
|
|
|
m_project = project;
|
|
m_project_view = projectview;
|
|
this->setEnabled(true);
|
|
|
|
//Conductor Signals
|
|
connect(m_project, SIGNAL(conductorAutoNumChanged()),
|
|
this,SLOT(conductorAutoNumChanged()));
|
|
connect(m_project,SIGNAL(conductorAutoNumRemoved()),
|
|
this,SLOT(conductorAutoNumChanged()));
|
|
connect(m_project,SIGNAL(conductorAutoNumAdded()),
|
|
this,SLOT(conductorAutoNumChanged()));
|
|
connect(m_project_view,SIGNAL(diagramActivated(DiagramView*)),
|
|
this,SLOT(setConductorActive(DiagramView*)));
|
|
|
|
//Element Signals
|
|
connect (m_project,SIGNAL(elementAutoNumRemoved(QString)),
|
|
this,SLOT(elementAutoNumChanged()));
|
|
connect (m_project,SIGNAL(elementAutoNumAdded(QString)),
|
|
this,SLOT(elementAutoNumChanged()));
|
|
|
|
//Folio Signals
|
|
connect (m_project,SIGNAL(folioAutoNumRemoved()),
|
|
this,SLOT(folioAutoNumChanged()));
|
|
connect (m_project,SIGNAL(folioAutoNumAdded()),
|
|
this,SLOT(folioAutoNumChanged()));
|
|
connect (this,
|
|
SIGNAL(folioAutoNumChanged(QString)),
|
|
&m_project_view->currentDiagram()->diagram()->border_and_titleblock,
|
|
SLOT (slot_setAutoPageNum(QString)));
|
|
connect(m_project, SIGNAL(defaultTitleBlockPropertiesChanged()),
|
|
this,SLOT(setActive()));
|
|
|
|
//Conductor, Element and Folio Signals
|
|
connect(m_project, &QETProject::destroyed,
|
|
this, &AutoNumberingDockWidget::projectClosed);
|
|
|
|
//Set Combobox Context
|
|
setContext();
|
|
|
|
ShortcutManager::instance().registerAction(ui->m_configure_pb, "autonum.configure",
|
|
tr("Autonumérotation"), Qt::CTRL | Qt::SHIFT | Qt::Key_P);
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::setContext
|
|
Add all itens to comboboxes
|
|
*/
|
|
void AutoNumberingDockWidget::setContext()
|
|
{
|
|
|
|
this->clear();
|
|
|
|
//Conductor Combobox
|
|
ui->m_conductor_cb->addItem("");
|
|
QList <QString> keys_conductor = m_project->conductorAutoNum().keys();
|
|
if (!keys_conductor.isEmpty()) {
|
|
foreach (QString str, keys_conductor)
|
|
{ ui->m_conductor_cb-> addItem(str); }
|
|
}
|
|
|
|
//Element Combobox
|
|
ui->m_element_cb->addItem("");
|
|
QList <QString> keys_element = m_project->elementAutoNum().keys();
|
|
if (!keys_element.isEmpty()) {
|
|
foreach (QString str, keys_element)
|
|
{ui->m_element_cb -> addItem(str);}
|
|
}
|
|
|
|
//Folio Combobox
|
|
ui->m_folio_cb->addItem("");
|
|
QList <QString> keys_folio = m_project->folioAutoNum().keys();
|
|
if (!keys_folio.isEmpty()) {
|
|
foreach (QString str, keys_folio)
|
|
{ ui->m_folio_cb -> addItem(str);}
|
|
}
|
|
|
|
this->setActive();
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::setConductorActive
|
|
@param dv: activated diagramview
|
|
*/
|
|
void AutoNumberingDockWidget::setConductorActive(DiagramView* dv) {
|
|
if (dv!=nullptr) {
|
|
QString conductor_autonum = dv->diagram()->conductorsAutonumName();
|
|
int conductor_index = ui->m_conductor_cb->findText(conductor_autonum);
|
|
ui->m_conductor_cb->setCurrentIndex(conductor_index);
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::setActive
|
|
Set current used autonumberings
|
|
*/
|
|
void AutoNumberingDockWidget::setActive()
|
|
{
|
|
|
|
if (m_project_view!=nullptr) {
|
|
//Conductor
|
|
if (m_project_view->currentDiagram()) {
|
|
QString conductor_autonum = m_project_view->currentDiagram()->diagram()->conductorsAutonumName();
|
|
int conductor_index = ui->m_conductor_cb->findText(conductor_autonum);
|
|
ui->m_conductor_cb->setCurrentIndex(conductor_index);
|
|
}
|
|
|
|
//Element
|
|
QString element_formula = m_project->elementAutoNumCurrentFormula();
|
|
QString active_element_autonum = m_project->elementCurrentAutoNum();
|
|
int el_index = ui->m_element_cb->findText(active_element_autonum);
|
|
ui->m_element_cb->setCurrentIndex(el_index);
|
|
|
|
//Folio
|
|
if (m_project->defaultTitleBlockProperties().folio == "%autonum") {
|
|
QString page_autonum = m_project->defaultTitleBlockProperties().auto_page_num;
|
|
int folio_index = ui->m_folio_cb->findText(page_autonum);
|
|
ui->m_folio_cb->setCurrentIndex(folio_index);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::conductorAutoNumChanged
|
|
Add new or remove conductor auto num from combobox
|
|
*/
|
|
void AutoNumberingDockWidget::conductorAutoNumChanged()
|
|
{
|
|
ui->m_conductor_cb->clear();
|
|
|
|
//Conductor Combobox
|
|
ui->m_conductor_cb->addItem("");
|
|
QList <QString> keys_conductor = m_project->conductorAutoNum().keys();
|
|
if (!keys_conductor.isEmpty()) {
|
|
foreach (QString str, keys_conductor)
|
|
{ ui->m_conductor_cb-> addItem(str); }
|
|
}
|
|
setActive();
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::on_m_conductor_cb_activated
|
|
Set new conductor AutoNum
|
|
*/
|
|
void AutoNumberingDockWidget::on_m_conductor_cb_activated(int)
|
|
{
|
|
QString current_autonum = ui->m_conductor_cb->currentText();
|
|
|
|
m_project->setCurrentConductorAutoNum(current_autonum);
|
|
m_project_view->currentDiagram()->diagram()->setConductorsAutonumName(current_autonum);
|
|
m_project_view->currentDiagram()->diagram()->loadCndFolioSeq();
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::elementAutoNumChanged
|
|
Add new or remove element auto num from combobox
|
|
*/
|
|
void AutoNumberingDockWidget::elementAutoNumChanged()
|
|
{
|
|
|
|
ui->m_element_cb->clear();
|
|
|
|
//Element Combobox
|
|
ui->m_element_cb->addItem("");
|
|
QList <QString> keys_element = m_project->elementAutoNum().keys();
|
|
if (!keys_element.isEmpty()) {
|
|
foreach (QString str, keys_element) {ui->m_element_cb -> addItem(str);}
|
|
}
|
|
setActive();
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::on_m_element_cb_activated
|
|
Set new element AutoNum
|
|
*/
|
|
void AutoNumberingDockWidget::on_m_element_cb_activated(int)
|
|
{
|
|
m_project->setCurrrentElementAutonum(ui->m_element_cb->currentText());
|
|
m_project_view->currentDiagram()->diagram()->loadElmtFolioSeq();
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::folioAutoNumChanged
|
|
Add new or remove folio auto num from combobox
|
|
*/
|
|
void AutoNumberingDockWidget::folioAutoNumChanged()
|
|
{
|
|
|
|
ui->m_folio_cb->clear();
|
|
|
|
//Folio Combobox
|
|
ui->m_folio_cb->addItem("");
|
|
QList <QString> keys_folio = m_project->folioAutoNum().keys();
|
|
if (!keys_folio.isEmpty()) {
|
|
foreach (QString str, keys_folio) { ui->m_folio_cb -> addItem(str);}
|
|
}
|
|
setActive();
|
|
}
|
|
|
|
/**
|
|
@brief AutoNumberingDockWidget::on_m_folio_cb_activated
|
|
Set new folio AutoNum
|
|
*/
|
|
void AutoNumberingDockWidget::on_m_folio_cb_activated(int) {
|
|
QString current_autonum = ui->m_folio_cb->currentText();
|
|
TitleBlockProperties ip = m_project -> defaultTitleBlockProperties();
|
|
if (current_autonum != "") {
|
|
ip.setAutoPageNum(current_autonum);
|
|
ip.folio = "%autonum";
|
|
m_project->setDefaultTitleBlockProperties(ip);
|
|
}
|
|
else {
|
|
ip.folio = "%id/%total";
|
|
m_project->setDefaultTitleBlockProperties(ip);
|
|
}
|
|
emit(folioAutoNumChanged(current_autonum));
|
|
}
|
|
|
|
void AutoNumberingDockWidget::on_m_configure_pb_clicked()
|
|
{
|
|
if (m_project)
|
|
{
|
|
ProjectPropertiesDialog ppd (m_project, this);
|
|
ppd.setCurrentPage(ProjectPropertiesDialog::Autonum);
|
|
ppd.exec();
|
|
}
|
|
}
|