Skip to content

Commit

Permalink
Qt6 port:
Browse files Browse the repository at this point in the history
* QApplication::setFallbackSessionManagementEnabled has been removed
* QString::medRef() has been removed. Use QString::mid() again.
* QTextStream::setCodec has been removed
* Use operator QVariant of the QFont class to make code Qt5 and Qt6 compatible
* Signature of QTreeWidget::mimeData() has changed in Qt6. Remove TreeWidget::mimeData() because it doesn't change the implementation
* QLayout::setMargin() is deprecated in Qt5 and has been removed in Qt6. Use QLayout::setContentsMargins()
* QDateTime::toTime_t() is deprecated in Qt5 and has been removed in Qt6. Use QDateTime::toSecsSinceEpoch()
* QDesktopWidget is deprecated in Qt5 and has been removed in Qt6. Use QScreen
  • Loading branch information
wwmayer committed Nov 1, 2022
1 parent 1337203 commit af0a014
Show file tree
Hide file tree
Showing 31 changed files with 50 additions and 52 deletions.
2 changes: 2 additions & 0 deletions src/Gui/AutoSaver.cpp
Expand Up @@ -145,7 +145,9 @@ void AutoSaver::saveDocument(const std::string& name, AutoSaveProperty& saver)
.arg(QString::fromUtf8(doc->TransientDir.getValue())));
if (file.open(QFile::WriteOnly)) {
QTextStream str(&file);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
str.setCodec("UTF-8");
#endif
str << "<?xml version='1.0' encoding='utf-8'?>\n"
<< "<AutoRecovery SchemaVersion=\"1\">\n";
str << " <Status>Created</Status>\n";
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/ComboView.cpp
Expand Up @@ -50,7 +50,7 @@ ComboView::ComboView(bool showModel, Gui::Document* pcDocument, QWidget *parent)

auto pLayout = new QGridLayout(this);
pLayout->setSpacing( 0 );
pLayout->setMargin ( 0 );
pLayout->setContentsMargins ( 0, 0, 0, 0 );

// tabs to switch between Tree/Properties and TaskPanel
tabs = new QTabWidget ();
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/DlgCustomizeImp.cpp
Expand Up @@ -59,11 +59,11 @@ DlgCustomizeImp::DlgCustomizeImp(QWidget* parent, Qt::WindowFlags fl)

customLayout = new QGridLayout( this );
customLayout->setSpacing( 6 );
customLayout->setMargin( 11 );
customLayout->setContentsMargins( 11, 11, 11, 11 );

layout = new QHBoxLayout;
layout->setSpacing( 6 );
layout->setMargin( 0 );
layout->setContentsMargins( 0, 0, 0, 0 );

buttonHelp = new QPushButton( this );
buttonHelp->setText(tr("&Help"));
Expand Down
8 changes: 2 additions & 6 deletions src/Gui/DocumentModel.cpp
Expand Up @@ -268,9 +268,7 @@ namespace Gui {
Document* doc = Application::Instance->activeDocument();
QFont font;
font.setBold(doc==&d);
QVariant variant;
variant.setValue<QFont>(font);
return variant;
return static_cast<QVariant>(font);
}

return QVariant();
Expand Down Expand Up @@ -325,9 +323,7 @@ namespace Gui {
App::DocumentObject* act = obj->getDocument()->getActiveObject();
QFont font;
font.setBold(obj==act);
QVariant variant;
variant.setValue<QFont>(font);
return variant;
return static_cast<QVariant>(font);
}

return QVariant();
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/DocumentRecovery.cpp
Expand Up @@ -355,7 +355,9 @@ void DocumentRecoveryPrivate::writeRecoveryInfo(const DocumentRecoveryPrivate::I
QFile file(info.xmlFile);
if (file.open(QFile::WriteOnly)) {
QTextStream str(&file);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
str.setCodec("UTF-8");
#endif
str << "<?xml version='1.0' encoding='utf-8'?>\n"
<< "<AutoRecovery SchemaVersion=\"1\">\n";
switch (info.status) {
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/EditorView.cpp
Expand Up @@ -113,7 +113,7 @@ EditorView::EditorView(QPlainTextEdit* editor, QWidget* parent)
hbox->setFrameShape(QFrame::StyledPanel);
hbox->setFrameShadow(QFrame::Sunken);
auto layout = new QVBoxLayout();
layout->setMargin(1);
layout->setContentsMargins(1, 1, 1, 1);
layout->addWidget(d->textEdit);
layout->addWidget(d->searchBar);
d->textEdit->setParent(hbox);
Expand Down
8 changes: 4 additions & 4 deletions src/Gui/FileDialog.cpp
Expand Up @@ -662,7 +662,7 @@ FileChooser::FileChooser ( QWidget * parent )
, _filter( QString() )
{
auto layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setContentsMargins( 0, 0, 0, 0 );
layout->setSpacing( 2 );

lineEdit = new QLineEdit ( this );
Expand Down Expand Up @@ -856,11 +856,11 @@ SelectModule::SelectModule (const QString& type, const SelectModule::Dict& types
group = new QButtonGroup(this);
gridLayout = new QGridLayout(this);
gridLayout->setSpacing(6);
gridLayout->setMargin(9);
gridLayout->setContentsMargins(9, 9, 9, 9);

gridLayout1 = new QGridLayout(groupBox);
gridLayout1->setSpacing(6);
gridLayout1->setMargin(9);
gridLayout1->setContentsMargins(9, 9, 9, 9);

int index = 0;
for (SelectModule::Dict::const_iterator it = types.begin(); it != types.end(); ++it) {
Expand Down Expand Up @@ -897,7 +897,7 @@ SelectModule::SelectModule (const QString& type, const SelectModule::Dict& types

hboxLayout = new QHBoxLayout();
hboxLayout->setSpacing(6);
hboxLayout->setMargin(0);
hboxLayout->setContentsMargins(0, 0, 0, 0);
spacerItem1 = new QSpacerItem(131, 31, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxLayout->addItem(spacerItem1);

Expand Down
2 changes: 1 addition & 1 deletion src/Gui/Flag.cpp
Expand Up @@ -183,7 +183,7 @@ QSize Flag::sizeHint() const
FlagLayout::FlagLayout(QWidget *parent, int margin, int spacing)
: QLayout(parent)
{
setMargin(margin);
setContentsMargins(margin, margin, margin, margin);
setSpacing(spacing);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Gui/GuiApplication.cpp
Expand Up @@ -62,7 +62,9 @@ GUIApplication::GUIApplication(int & argc, char ** argv)
{
connect(this, SIGNAL(commitDataRequest(QSessionManager &)),
SLOT(commitData(QSessionManager &)), Qt::DirectConnection);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
setFallbackSessionManagementEnabled(false);
#endif
}

GUIApplication::~GUIApplication()
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/ManualAlignment.cpp
Expand Up @@ -394,7 +394,7 @@ class AlignmentView : public Gui::AbstractSplitView

auto vbox = new QFrame(this);
auto layout = new QVBoxLayout();
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
vbox->setLayout(layout);

Expand Down
4 changes: 2 additions & 2 deletions src/Gui/PropertyView.cpp
Expand Up @@ -72,7 +72,7 @@ PropertyView::PropertyView(QWidget *parent)
{
auto pLayout = new QGridLayout( this );
pLayout->setSpacing(0);
pLayout->setMargin (0);
pLayout->setContentsMargins(0, 0, 0, 0);

timer = new QTimer(this);
timer->setSingleShot(true);
Expand Down Expand Up @@ -560,7 +560,7 @@ PropertyDockView::PropertyDockView(Gui::Document* pcDocument, QWidget *parent)
auto view = new PropertyView(this);
auto pLayout = new QGridLayout(this);
pLayout->setSpacing(0);
pLayout->setMargin (0);
pLayout->setContentsMargins(0, 0, 0, 0);
pLayout->addWidget(view, 0, 0);

resize( 200, 400 );
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/QSint/actionpanel/actiongroup.cpp
Expand Up @@ -45,7 +45,7 @@ void ActionGroup::init(bool header)
myScheme = ActionPanelScheme::defaultScheme();

QVBoxLayout *vbl = new QVBoxLayout();
vbl->setMargin(0);
vbl->setContentsMargins(0, 0, 0, 0);
vbl->setSpacing(0);
setLayout(vbl);

Expand Down
2 changes: 1 addition & 1 deletion src/Gui/QSint/actionpanel/actionpanel.cpp
Expand Up @@ -26,7 +26,7 @@ ActionPanel::ActionPanel(QWidget *parent) :
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);

QVBoxLayout *vbl = new QVBoxLayout();
vbl->setMargin(8);
vbl->setContentsMargins(8, 8, 8, 8);
vbl->setSpacing(8);
setLayout(vbl);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/QSint/actionpanel/taskgroup_p.cpp
Expand Up @@ -25,7 +25,7 @@ TaskGroup::TaskGroup(QWidget *parent, bool hasHeader)
setScheme(ActionPanelScheme::defaultScheme());

QVBoxLayout *vbl = new QVBoxLayout();
vbl->setMargin(4);
vbl->setContentsMargins(4, 4, 4, 4);
vbl->setSpacing(0);
setLayout(vbl);

Expand Down Expand Up @@ -63,7 +63,7 @@ bool TaskGroup::addWidget(QWidget *widget, bool addToLayout, bool addStretch)

if (addStretch) {
QHBoxLayout *hbl = new QHBoxLayout();
hbl->setMargin(0);
hbl->setContentsMargins(0, 0, 0, 0);
hbl->setSpacing(0);
hbl->addWidget(widget);
hbl->addStretch();
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/QSint/actionpanel/taskheader_p.cpp
Expand Up @@ -40,7 +40,7 @@ TaskHeader::TaskHeader(const QIcon &icon, const QString &title, bool expandable,
connect(myTitle, SIGNAL(clicked()), this, SLOT(fold()));

QHBoxLayout *hbl = new QHBoxLayout();
hbl->setMargin(2);
hbl->setContentsMargins(2, 2, 2, 2);
setLayout(hbl);

hbl->addWidget(myTitle);
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/ReportView.cpp
Expand Up @@ -60,7 +60,7 @@ ReportView::ReportView( QWidget* parent )
resize( 529, 162 );
auto tabLayout = new QGridLayout( this );
tabLayout->setSpacing( 0 );
tabLayout->setMargin( 0 );
tabLayout->setContentsMargins( 0, 0, 0, 0 );

tabWidget = new QTabWidget( this );
tabWidget->setObjectName(QString::fromUtf8("tabWidget"));
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/SelectionView.cpp
Expand Up @@ -62,7 +62,7 @@ SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent)

QVBoxLayout* vLayout = new QVBoxLayout(this);
vLayout->setSpacing(0);
vLayout->setMargin (0);
vLayout->setContentsMargins(0, 0, 0, 0);

QLineEdit* searchBox = new QLineEdit(this);
searchBox->setPlaceholderText(tr("Search"));
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/Splashscreen.cpp
Expand Up @@ -412,7 +412,9 @@ void AboutDialog::showCredits()
creditsHTML += QString::fromLatin1("</h2><ul>");

QTextStream stream(&creditsFile);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
stream.setCodec("UTF-8");
#endif
QString line;
while (stream.readLineInto(&line)) {
if (!line.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/Thumbnail.cpp
Expand Up @@ -116,7 +116,7 @@ void Thumbnail::SaveDocFile (Base::Writer &writer) const

if (!px.isNull()) {
// according to specification add some meta-information to the image
uint mt = QDateTime::currentDateTimeUtc().toTime_t();
qint64 mt = QDateTime::currentDateTimeUtc().toSecsSinceEpoch();
QString mtime = QString::fromLatin1("%1").arg(mt);
img.setText(QLatin1String("Software"), qApp->applicationName());
img.setText(QLatin1String("Thumb::Mimetype"), QLatin1String("application/x-extension-fcstd"));
Expand Down
9 changes: 2 additions & 7 deletions src/Gui/Tree.cpp
Expand Up @@ -1489,11 +1489,6 @@ void TreeWidget::startDrag(Qt::DropActions supportedActions)
}
}

QMimeData* TreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const
{
return QTreeWidget::mimeData(items);
}

bool TreeWidget::dropMimeData(QTreeWidgetItem* parent, int index,
const QMimeData* data, Qt::DropAction action)
{
Expand Down Expand Up @@ -3028,7 +3023,7 @@ TreePanel::TreePanel(const char* name, QWidget* parent)

auto pLayout = new QVBoxLayout(this);
pLayout->setSpacing(0);
pLayout->setMargin(0);
pLayout->setContentsMargins(0, 0, 0, 0);
pLayout->addWidget(this->treeWidget);
connect(this->treeWidget, SIGNAL(emitSearchObjects()),
this, SLOT(showEditor()));
Expand Down Expand Up @@ -3116,7 +3111,7 @@ TreeDockWidget::TreeDockWidget(Gui::Document* pcDocument, QWidget* parent)
auto panel = new TreePanel("TreeView", this);
auto pLayout = new QGridLayout(this);
pLayout->setSpacing(0);
pLayout->setMargin(0);
pLayout->setContentsMargins(0, 0, 0, 0);
pLayout->addWidget(panel, 0, 0);
}

Expand Down
1 change: 0 additions & 1 deletion src/Gui/Tree.h
Expand Up @@ -124,7 +124,6 @@ class TreeWidget : public QTreeWidget, public SelectionObserver
bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data,
Qt::DropAction action) override;
Qt::DropActions supportedDropActions () const override;
QMimeData * mimeData (const QList<QTreeWidgetItem *> items) const override;
void dragEnterEvent(QDragEnterEvent * event) override;
void dragLeaveEvent(QDragLeaveEvent * event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
Expand Down
6 changes: 3 additions & 3 deletions src/Gui/Widgets.cpp
Expand Up @@ -1046,7 +1046,7 @@ LabelButton::LabelButton (QWidget * parent)
: QWidget(parent)
{
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(1);

label = new QLabel(this);
Expand Down Expand Up @@ -1202,7 +1202,7 @@ StatusWidget::StatusWidget(QWidget* parent)

auto gridLayout = new QGridLayout(this);
gridLayout->setSpacing(6);
gridLayout->setMargin(9);
gridLayout->setContentsMargins(9, 9, 9, 9);
gridLayout->addWidget(label, 0, 0, 1, 1);
}

Expand Down Expand Up @@ -1411,7 +1411,7 @@ LabelEditor::LabelEditor (QWidget * parent)
{
type = String;
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(2);

lineEdit = new QLineEdit(this);
Expand Down
6 changes: 4 additions & 2 deletions src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -1506,7 +1506,7 @@ PropertyEditorWidget::PropertyEditorWidget (QWidget * parent)
: QWidget(parent)
{
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(2);

lineEdit = new QLineEdit(this);
Expand Down Expand Up @@ -3065,7 +3065,9 @@ void PropertyStringListItem::setValue(const QVariant& value)
QStringList values = value.toStringList();
QString data;
QTextStream str(&data);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
str.setCodec("UTF-8");
#endif

str << "[";
for (QStringList::Iterator it = values.begin(); it != values.end(); ++it) {
Expand Down Expand Up @@ -4284,7 +4286,7 @@ LinkLabel::LinkLabel (QWidget * parent, const App::Property *prop)
: QWidget(parent), objProp(prop), dlg(nullptr)
{
auto layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(1);

label = new QLabel(this);
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Part/App/FaceMakerCheese.cpp
Expand Up @@ -22,6 +22,7 @@

#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <Bnd_Box.hxx>
# include <BRep_Builder.hxx>
# include <BRep_Tool.hxx>
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Part/Gui/DlgFilletEdges.cpp
Expand Up @@ -429,7 +429,7 @@ void DlgFilletEdges::onSelectEdge(const QString& subelement, int type)
void DlgFilletEdges::onSelectEdgesOfFace(const QString& subelement, int type)
{
bool ok;
int index = subelement.midRef(4).toInt(&ok);
int index = subelement.mid(4).toInt(&ok);
if (ok) {
try {
const TopoDS_Shape& face = d->all_faces.FindKey(index);
Expand Down
4 changes: 1 addition & 3 deletions src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp
Expand Up @@ -735,9 +735,7 @@ void TaskExtrudeParameters::translateFaceName()

if (ok) {
ui->lineFaceName->setText(QString::fromLatin1("%1:%2%3")
.arg(parts[0],
tr("Face"),
QString(faceId)));
.arg(parts[0], tr("Face")).arg(faceId));
}
else {
ui->lineFaceName->setText(parts[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/Gui/SketcherSettings.cpp
Expand Up @@ -51,7 +51,7 @@ SketcherSettings::SketcherSettings(QWidget* parent)
ui->setupUi(this);
QGridLayout* gridLayout = new QGridLayout(ui->placeholder);
gridLayout->setSpacing(0);
gridLayout->setMargin(0);
gridLayout->setContentsMargins(0, 0, 0, 0);
form = new SketcherGeneralWidget(ui->placeholder);
gridLayout->addWidget(form, 0, 0, 1, 1);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Mod/Sketcher/Gui/SoDatumLabel.cpp
Expand Up @@ -36,7 +36,6 @@
# include <cfloat>
# include <algorithm>
# include <QFontMetrics>
# include <QGLWidget>
# include <QPainter>
# include <QPen>
# include <Inventor/SoPrimitiveVertex.h>
Expand Down Expand Up @@ -113,7 +112,7 @@ void SoDatumLabel::drawImage()
return;
}

QFont font(QString::fromLatin1(name.getValue()), size.getValue());
QFont font(QString::fromLatin1(name.getValue(), -1), size.getValue());
QFontMetrics fm(font);
QString str = QString::fromUtf8(s[0].getString());

Expand Down

0 comments on commit af0a014

Please sign in to comment.