mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-13 10:04:13 +02:00
325b895d0b
Double-clicking a placed element (or right-click > "Éditer l'élément")
opens its properties via Element::editProperty(), which constructs a
PropertiesEditorDialog with a real parent (QApplication::activeWindow()).
On macOS, a QDialog that has both a parent and Qt::WindowModal set falls
back to Cocoa's automatic sheet presentation. Reports (and this
codebase's own existing workarounds) indicate this can render stuck
centered on screen, non-draggable, with symmetric resize -- rather than
a proper attached, movable window -- unlike Linux/X11 where the same
dialog behaves as a normal draggable QDialog.
Two other dialogs in this codebase already explicitly opt into the
correct macOS sheet presentation for this exact reason:
ElementDialog::setUpWidget() and DiagramPropertiesDialog's setup both do
setWindowModality(Qt::WindowModal);
#ifdef Q_OS_MACOS
setWindowFlags(Qt::Sheet);
#endif
PropertiesEditorDialog -- used for editing Element, QetShapeItem, and
DiagramImageItem properties, all reached via double-click on a diagram
item -- had neither this opt-in nor an opt-out, so it likely fell into
the same automatic-sheet behavior but without the explicit flag,
matching the reported "stuck centered, can't drag" symptom.
Fix: apply the same setWindowModality()/Q_OS_MACOS Qt::Sheet pattern
already used by the other two dialogs, in PropertiesEditorDialog's
constructor -- fixing all three call sites (element, shape, and image
property editing) at once, since they share this one dialog class.
Verified: clean rebuild, all three call sites (element.cpp,
qetshapeitem.cpp, diagramimageitem.cpp) recompiled and linked
successfully with no errors or warnings.
Not verified: the actual reported symptom is macOS/Cocoa-specific
window presentation behavior, which cannot be reproduced or confirmed
fixed in this Linux/Xvfb sandbox -- no macOS environment is available
here. Confidence rests on the exact same fix pattern already being
established and presumably working for two other dialogs in this
codebase for the identical class of problem.
105 lines
3.1 KiB
C++
105 lines
3.1 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 PROPERTIESEDITORDIALOG_H
|
|
#define PROPERTIESEDITORDIALOG_H
|
|
|
|
#include <QDialog>
|
|
#include <QDialogButtonBox>
|
|
#include <QVBoxLayout>
|
|
#include <QAbstractButton>
|
|
|
|
/**
|
|
@brief The PropertiesEditorDialog class
|
|
Create a dialog to edit some properties of a thing.
|
|
Only create a instance of this class and call exec,
|
|
all is done for you in this class.
|
|
The first argument (a template) must be a subclass
|
|
of QWidget and provide the 3 methods below :
|
|
QString::title()
|
|
void::apply()
|
|
void::reset()
|
|
You can subclass the interface PropertiesEditorWidget
|
|
who provide all this methods.
|
|
This dialog take ownership of the editor,
|
|
so the editor will be deleted by this dialog
|
|
*/
|
|
class PropertiesEditorDialog : public QDialog
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
template<typename T>
|
|
PropertiesEditorDialog(T editor, QWidget *parent = nullptr) :
|
|
QDialog (parent)
|
|
{
|
|
// Without this, a QWidget-modal QDialog with a parent falls
|
|
// back to macOS's automatic sheet presentation, which some
|
|
// Qt/Cocoa versions render stuck centered on screen and
|
|
// non-draggable rather than as a proper attached sheet
|
|
// (bugtracker #275). Other dialogs in this codebase already
|
|
// opt in explicitly (see ElementDialog, DiagramPropertiesDialog)
|
|
// -- this one was missing it.
|
|
setWindowModality(Qt::WindowModal);
|
|
#ifdef Q_OS_MACOS
|
|
setWindowFlags(Qt::Sheet);
|
|
#endif
|
|
|
|
//Set dialog title
|
|
setWindowTitle(editor->title());
|
|
// Reparent the editor,
|
|
// to be deleted at the same time of this dialog
|
|
editor->setParent(this);
|
|
|
|
//Build the dialog
|
|
QVBoxLayout *vlayout = new QVBoxLayout(this);
|
|
vlayout->addWidget(editor);
|
|
QDialogButtonBox *button_box = new QDialogButtonBox (
|
|
QDialogButtonBox::Apply
|
|
| QDialogButtonBox::Cancel
|
|
| QDialogButtonBox::Reset,
|
|
this);
|
|
vlayout->addWidget(button_box);
|
|
|
|
//Setup connection between button box and the editor
|
|
connect(button_box,
|
|
&QDialogButtonBox::clicked,
|
|
[editor, button_box, this]
|
|
(QAbstractButton *button)
|
|
{
|
|
switch(button_box->buttonRole(button))
|
|
{
|
|
case QDialogButtonBox::RejectRole:
|
|
editor->reset();
|
|
this->reject();
|
|
break;
|
|
case QDialogButtonBox::ResetRole:
|
|
editor->reset();
|
|
break;
|
|
case QDialogButtonBox::ApplyRole:
|
|
editor->apply();
|
|
this->accept();
|
|
break;
|
|
default:
|
|
editor->reset();
|
|
this->reject();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
#endif // PROPERTIESEDITORDIALOG_H
|