From aa9a1fc07fb612547c1d1c5074d669b2dd258af9 Mon Sep 17 00:00:00 2001 From: Silarn Date: Wed, 3 Jul 2019 13:04:27 -0500 Subject: [PATCH 1/3] Refactor obsolete methods --- src/browserdialog.cpp | 5 ++--- src/downloadmanager.cpp | 9 +++++++-- src/listdialog.cpp | 2 +- src/main.cpp | 4 ++-- src/moapplication.cpp | 2 +- src/modinfobackup.h | 2 ++ src/modinfodialogconflicts.cpp | 9 ++++----- src/modinfodialogfiletree.h | 3 +++ src/modinfodialognexus.h | 2 ++ src/modinfoforeign.cpp | 2 +- src/modinforegular.cpp | 2 +- src/modinfoseparator.h | 2 ++ src/modlist.cpp | 2 +- src/overwriteinfodialog.cpp | 1 - src/pluginlist.cpp | 2 +- src/previewgenerator.cpp | 5 +---- src/profile.cpp | 2 +- src/transfersavesdialog.cpp | 2 +- 18 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/browserdialog.cpp b/src/browserdialog.cpp index e186ad63d..c34d211f9 100644 --- a/src/browserdialog.cpp +++ b/src/browserdialog.cpp @@ -138,9 +138,8 @@ void BrowserDialog::maximizeWidth() int contentWidth = getCurrentView()->page()->contentsSize().width(); - QDesktopWidget screen; - int currentScreen = screen.screenNumber(this); - int screenWidth = screen.screenGeometry(currentScreen).size().width(); + QScreen* screen = this->window()->windowHandle()->screen(); + int screenWidth = screen->geometry().size().width(); int targetWidth = std::min(std::max(viewportWidth, contentWidth) + frameWidth, screenWidth); this->resize(targetWidth, height()); diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 648b102ad..ec1faed41 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -717,7 +717,7 @@ void DownloadManager::refreshAlphabeticalTranslation() m_AlphabeticalTranslation.push_back(pos); } - qSort(m_AlphabeticalTranslation.begin(), m_AlphabeticalTranslation.end(), LessThanWrapper(this)); + std::sort(m_AlphabeticalTranslation.begin(), m_AlphabeticalTranslation.end(), LessThanWrapper(this)); } @@ -1155,7 +1155,12 @@ QDateTime DownloadManager::getFileTime(int index) const DownloadInfo *info = m_ActiveDownloads.at(index); if (!info->m_Created.isValid()) { - info->m_Created = QFileInfo(info->m_Output).created(); + QFileInfo fileInfo(info->m_Output); + info->m_Created = fileInfo.birthTime(); + if (!info->m_Created.isValid()) + info->m_Created = fileInfo.metadataChangeTime(); + if (!info->m_Created.isValid()) + info->m_Created = fileInfo.lastModified(); } return info->m_Created; diff --git a/src/listdialog.cpp b/src/listdialog.cpp index 52bba80d8..b98570702 100644 --- a/src/listdialog.cpp +++ b/src/listdialog.cpp @@ -61,7 +61,7 @@ void ListDialog::on_filterEdit_textChanged(QString filter) if (newChoices.length() == 1) { QListWidgetItem *item = ui->choiceList->item(0); - ui->choiceList->setItemSelected(item, true); + item->setSelected(true); ui->choiceList->setCurrentItem(item); } diff --git a/src/main.cpp b/src/main.cpp index c6c87a64d..b83e581b8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -646,8 +646,8 @@ int runApplication(MOApplication &application, SingleInstance &instance, const int monitor = settings.value("window_monitor").toInt(); if (monitor != -1) { - QDesktopWidget* desktop = QApplication::desktop(); - const QPoint center = desktop->availableGeometry(monitor).center(); + QGuiApplication::screens().at(monitor)->geometry().center(); + const QPoint center = QGuiApplication::screens().at(monitor)->geometry().center(); splash.move(center - splash.rect().center()); } } diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 5652833a8..e07db4372 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -50,7 +50,7 @@ class ProxyStyle : public QProxyStyle { if(element == QStyle::PE_IndicatorItemViewItemDrop) { painter->setRenderHint(QPainter::Antialiasing, true); - QColor col(option->palette.foreground().color()); + QColor col(option->palette.windowText().color()); QPen pen(col); pen.setWidth(2); col.setAlpha(50); diff --git a/src/modinfobackup.h b/src/modinfobackup.h index cab613c95..393c2e388 100644 --- a/src/modinfobackup.h +++ b/src/modinfobackup.h @@ -6,6 +6,8 @@ class ModInfoBackup : public ModInfoRegular { + Q_OBJECT + friend class ModInfo; public: diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 511d48ad7..6dd1fe4e6 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -7,7 +7,6 @@ using namespace MOShared; using namespace MOBase; -namespace shell = MOBase::shell; // if there are more than 50 selected items in the conflict tree, don't bother // checking whether menu items apply to them, just show all of them @@ -935,7 +934,7 @@ ConflictItem GeneralConflictsTab::createOverwriteItem( auto origin = ToQString(ds.getOriginByID(alternatives.back().first).getName()); return ConflictItem( - ToQString(altString), std::move(relativeName), QString::null, index, + ToQString(altString), std::move(relativeName), QString(), index, std::move(fileName), true, std::move(origin), archive); } @@ -943,8 +942,8 @@ ConflictItem GeneralConflictsTab::createNoConflictItem( FileEntry::Index index, bool archive, QString fileName, QString relativeName) { return ConflictItem( - QString::null, std::move(relativeName), QString::null, index, - std::move(fileName), false, QString::null, archive); + QString(), std::move(relativeName), QString(), index, + std::move(fileName), false, QString(), archive); } ConflictItem GeneralConflictsTab::createOverwrittenItem( @@ -958,7 +957,7 @@ ConflictItem GeneralConflictsTab::createOverwrittenItem( QString altOrigin = after; return ConflictItem( - QString::null, std::move(relativeName), std::move(after), + QString(), std::move(relativeName), std::move(after), index, std::move(fileName), true, std::move(altOrigin), archive); } diff --git a/src/modinfodialogfiletree.h b/src/modinfodialogfiletree.h index f9fa62d4b..427738998 100644 --- a/src/modinfodialogfiletree.h +++ b/src/modinfodialogfiletree.h @@ -2,9 +2,12 @@ #define MODINFODIALOGFILETREE_H #include "modinfodialogtab.h" +#include class FileTreeTab : public ModInfoDialogTab { + Q_OBJECT; + public: FileTreeTab(ModInfoDialogTabContext cx); diff --git a/src/modinfodialognexus.h b/src/modinfodialognexus.h index 7f894dbf7..1cfa20574 100644 --- a/src/modinfodialognexus.h +++ b/src/modinfodialognexus.h @@ -32,6 +32,8 @@ class NexusTabWebpage : public QWebEnginePage class NexusTab : public ModInfoDialogTab { + Q_OBJECT; + public: NexusTab(ModInfoDialogTabContext cx); diff --git a/src/modinfoforeign.cpp b/src/modinfoforeign.cpp index b599d4ebf..7312d5b78 100644 --- a/src/modinfoforeign.cpp +++ b/src/modinfoforeign.cpp @@ -55,7 +55,7 @@ ModInfoForeign::ModInfoForeign(const QString &modName, PluginContainer *pluginContainer) : ModInfoWithConflictInfo(pluginContainer, directoryStructure), m_ReferenceFile(referenceFile), m_Archives(archives) { - m_CreationTime = QFileInfo(referenceFile).created(); + m_CreationTime = QFileInfo(referenceFile).birthTime(); switch (modType) { case ModInfo::EModType::MOD_DLC: m_Name = tr("DLC: ") + modName; diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp index 448447e13..12137bcbd 100644 --- a/src/modinforegular.cpp +++ b/src/modinforegular.cpp @@ -39,7 +39,7 @@ ModInfoRegular::ModInfoRegular(PluginContainer *pluginContainer, const IPluginGa , m_NexusBridge(pluginContainer) { testValid(); - m_CreationTime = QFileInfo(path.absolutePath()).created(); + m_CreationTime = QFileInfo(path.absolutePath()).birthTime(); // read out the meta-file for information readMeta(); if (m_GameName.compare(game->gameShortName(), Qt::CaseInsensitive) != 0) diff --git a/src/modinfoseparator.h b/src/modinfoseparator.h index 3560d7865..4b1e52173 100644 --- a/src/modinfoseparator.h +++ b/src/modinfoseparator.h @@ -6,6 +6,8 @@ class ModInfoSeparator: public ModInfoRegular { + Q_OBJECT; + friend class ModInfo; public: diff --git a/src/modlist.cpp b/src/modlist.cpp index e2398cd65..abe4fd5db 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -1322,7 +1322,7 @@ bool ModList::moveSelection(QAbstractItemView *itemView, int direction) QModelIndexList rows = selectionModel->selectedRows(); if (direction > 0) { for (int i = 0; i < rows.size() / 2; ++i) { - rows.swap(i, rows.size() - i - 1); + rows.swapItemsAt(i, rows.size() - i - 1); } } for (QModelIndex idx : rows) { diff --git a/src/overwriteinfodialog.cpp b/src/overwriteinfodialog.cpp index 0a884ac9b..a9ef8bef8 100644 --- a/src/overwriteinfodialog.cpp +++ b/src/overwriteinfodialog.cpp @@ -32,7 +32,6 @@ using namespace MOBase; class MyFileSystemModel : public QFileSystemModel { - public: MyFileSystemModel(QObject *parent) : QFileSystemModel(parent), m_RegularColumnCount(0) {} diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 2edb92f52..85160a88e 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -1304,7 +1304,7 @@ bool PluginList::eventFilter(QObject *obj, QEvent *event) } if (keyEvent->key() == Qt::Key_Down) { for (int i = 0; i < rows.size() / 2; ++i) { - rows.swap(i, rows.size() - i - 1); + rows.swapItemsAt(i, rows.size() - i - 1); } } for (QModelIndex idx : rows) { diff --git a/src/previewgenerator.cpp b/src/previewgenerator.cpp index 280d69aa4..f317393e8 100644 --- a/src/previewgenerator.cpp +++ b/src/previewgenerator.cpp @@ -22,14 +22,11 @@ along with Mod Organizer. If not, see . #include #include #include -#include #include PreviewGenerator::PreviewGenerator() { - - QDesktopWidget desk; - m_MaxSize = desk.screenGeometry().size() * 0.8; + m_MaxSize = QGuiApplication::primaryScreen()->size() * 0.8; } void PreviewGenerator::registerPlugin(MOBase::IPluginPreview *plugin) diff --git a/src/profile.cpp b/src/profile.cpp index ef3870271..4ac15333d 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -899,7 +899,7 @@ void Profile::rename(const QString &newName) { QDir profileDir(Settings::instance().getProfileDirectory()); profileDir.rename(name(), newName); - m_Directory = profileDir.absoluteFilePath(newName); + m_Directory.setPath(profileDir.absoluteFilePath(newName)); } QVariant Profile::setting(const QString §ion, const QString &name, diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp index 130df14f3..451f56d4d 100644 --- a/src/transfersavesdialog.cpp +++ b/src/transfersavesdialog.cpp @@ -61,7 +61,7 @@ class DummySave : public ISaveGame virtual QDateTime getCreationTime() const override { - return QFileInfo(m_File).created(); + return QFileInfo(m_File).birthTime(); } virtual QString getSaveGroupIdentifier() const override From 3a2f056e8adf07f31ea1f6b2856a6d57da1f4777 Mon Sep 17 00:00:00 2001 From: Silarn Date: Wed, 3 Jul 2019 14:12:38 -0500 Subject: [PATCH 2/3] More refactoring --- src/browserdialog.cpp | 1 - src/main.cpp | 5 ++++- src/mainwindow.cpp | 7 ++++--- src/modinfodialogconflicts.cpp | 2 +- src/pch.h | 1 - 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/browserdialog.cpp b/src/browserdialog.cpp index c34d211f9..70190433e 100644 --- a/src/browserdialog.cpp +++ b/src/browserdialog.cpp @@ -35,7 +35,6 @@ along with Mod Organizer. If not, see . #include #include #include -#include #include diff --git a/src/main.cpp b/src/main.cpp index b83e581b8..1e60483f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -645,10 +645,13 @@ int runApplication(MOApplication &application, SingleInstance &instance, if (settings.contains("window_monitor")) { const int monitor = settings.value("window_monitor").toInt(); - if (monitor != -1) { + if (monitor != -1 && QGuiApplication::screens().size() > monitor) { QGuiApplication::screens().at(monitor)->geometry().center(); const QPoint center = QGuiApplication::screens().at(monitor)->geometry().center(); splash.move(center - splash.rect().center()); + } else { + const QPoint center = QGuiApplication::primaryScreen()->geometry().center(); + splash.move(center - splash.rect().center()); } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7681b4824..9726b27b9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -99,7 +99,6 @@ along with Mod Organizer. If not, see . #include #include #include -#include #include #include #include @@ -1340,7 +1339,7 @@ void MainWindow::displaySaveGameInfo(QListWidgetItem *newItem) } m_CurrentSaveView->setSave(save); - QRect screenRect = QApplication::desktop()->availableGeometry(m_CurrentSaveView); + QRect screenRect = m_CurrentSaveView->window()->windowHandle()->screen()->geometry(); QPoint pos = QCursor::pos(); if (pos.x() + m_CurrentSaveView->width() > screenRect.right()) { @@ -2279,7 +2278,9 @@ void MainWindow::storeSettings(QSettings &settings) { settings.setValue("menubar_visible", m_menuBarVisible); settings.setValue("statusbar_visible", m_statusBarVisible); settings.setValue("window_split", ui->splitter->saveState()); - settings.setValue("window_monitor", QApplication::desktop()->screenNumber(this)); + QScreen *screen = this->window()->windowHandle()->screen(); + int screenId = QGuiApplication::screens().indexOf(screen); + settings.setValue("window_monitor", screenId); settings.setValue("log_split", ui->topLevelSplitter->saveState()); settings.setValue("browser_geometry", m_IntegratedBrowser.saveGeometry()); settings.setValue("filters_visible", ui->displayCategoriesBtn->isChecked()); diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 6dd1fe4e6..698c85349 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -1224,5 +1224,5 @@ std::optional AdvancedConflictsTab::createItem( return ConflictItem( std::move(beforeQS), std::move(relativeName), std::move(afterQS), - index, std::move(fileName), hasAlts, QString::null, archive); + index, std::move(fileName), hasAlts, QString(), archive); } diff --git a/src/pch.h b/src/pch.h index 1d8df43ac..9640b09d8 100644 --- a/src/pch.h +++ b/src/pch.h @@ -91,7 +91,6 @@ #include #include #include -#include #include #include #include From 7879ea2c623521115eafeef4ad788eef8c18cc2c Mon Sep 17 00:00:00 2001 From: Silarn Date: Thu, 4 Jul 2019 15:09:49 -0500 Subject: [PATCH 3/3] Fix issue if widget isn't on a window --- src/mainwindow.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9726b27b9..6c6eeee7a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1339,7 +1339,12 @@ void MainWindow::displaySaveGameInfo(QListWidgetItem *newItem) } m_CurrentSaveView->setSave(save); - QRect screenRect = m_CurrentSaveView->window()->windowHandle()->screen()->geometry(); + QWindow *window = m_CurrentSaveView->window()->windowHandle(); + QRect screenRect; + if (window == nullptr) + screenRect = QGuiApplication::primaryScreen()->geometry(); + else + screenRect = window->screen()->geometry(); QPoint pos = QCursor::pos(); if (pos.x() + m_CurrentSaveView->width() > screenRect.right()) {