mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
Final clean up for pull request
Signed-off-by: Ice Yeti <101294194+IceYetiWins@users.noreply.github.com>
This commit is contained in:
parent
cb105b720b
commit
08d9e57d96
10 changed files with 44 additions and 44 deletions
|
|
@ -607,11 +607,11 @@ void InstanceList::providerUpdated()
|
|||
}
|
||||
}
|
||||
|
||||
QList<BaseInstance*> InstanceList::getAllInstances()
|
||||
QList<BaseInstance*> InstanceList::getAllInstances() const
|
||||
{
|
||||
QList<BaseInstance*> instanceList;
|
||||
|
||||
for (auto& inst : instances) {
|
||||
for (const auto& inst : instances) {
|
||||
instanceList.append(inst.get());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ class InstanceList : public QAbstractListModel {
|
|||
InstListError loadList();
|
||||
void saveNow();
|
||||
|
||||
QList<BaseInstance*> getAllInstances();
|
||||
QList<BaseInstance*> getAllInstances() const;
|
||||
/* O(n) */
|
||||
BaseInstance* getInstanceById(QString id) const;
|
||||
/* O(n) */
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ void MultiWorldList::startWatching()
|
|||
|
||||
m_isWatching = true;
|
||||
|
||||
for (QDir dir : m_dirs) {
|
||||
for (const QDir& dir : m_dirs) {
|
||||
if (m_watcher->addPath(dir.absolutePath())) {
|
||||
qDebug() << "Started watching" << dir.absolutePath();
|
||||
} else {
|
||||
|
|
@ -157,7 +157,7 @@ QList<QString> MultiWorldList::instDirPaths() const
|
|||
{
|
||||
QList<QString> dirList;
|
||||
|
||||
for (BaseInstance* instance : allInstances) {
|
||||
for (BaseInstance const* instance : allInstances) {
|
||||
dirList.append(QFileInfo(instance->instanceRoot()).absoluteFilePath());
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +223,7 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const
|
|||
|
||||
QLocale locale;
|
||||
|
||||
auto& instanceWorld = m_worlds[row];
|
||||
const auto& instanceWorld = m_worlds[row];
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
switch (column) {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class MultiWorldList : public QAbstractListModel {
|
|||
/// process data from drop action
|
||||
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
|
||||
/// what drag actions do we support?
|
||||
int64_t calculateWorldSize(const QFileInfo& file);
|
||||
static int64_t calculateWorldSize(const QFileInfo& file);
|
||||
virtual Qt::DropActions supportedDragActions() const;
|
||||
|
||||
/// what drop actions do we support?
|
||||
|
|
|
|||
|
|
@ -338,19 +338,9 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||
|
||||
connect(this, &MainWindow::selectInstance, view, &InstanceView::selectInstance);
|
||||
}
|
||||
// Create the all worlds widget
|
||||
|
||||
// All worlds toggle
|
||||
{
|
||||
QList<BaseInstance*> allInstances = APPLICATION->instances()->getAllInstances();
|
||||
|
||||
allWorlds = new MultiWorldList(allInstances);
|
||||
allWorlds->update();
|
||||
allWorldsPage = new MultiWorldListPage(allWorlds);
|
||||
|
||||
ui->horizontalLayout->addWidget(allWorldsPage);
|
||||
|
||||
allWorldsPage->setVisible(false);
|
||||
ui->instanceToolBar->setVisibilityState(QByteArray::fromBase64(instanceToolbarSetting->get().toString().toUtf8()));
|
||||
|
||||
connect(ui->actionAllWorlds, &QAction::toggled, this, &MainWindow::onAllWorldsToggled);
|
||||
connect(allWorldsPage, &MultiWorldListPage::worldJoined, this, &MainWindow::worldJoined);
|
||||
}
|
||||
|
|
@ -878,14 +868,13 @@ void MainWindow::worldJoined(BaseInstance* instance)
|
|||
void MainWindow::toggleAllWorldsScreen(bool toggled)
|
||||
{
|
||||
if (toggled) {
|
||||
QList<BaseInstance*> allInstances = APPLICATION->instances()->getAllInstances();
|
||||
QList<BaseInstance*> const allInstances = APPLICATION->instances()->getAllInstances();
|
||||
|
||||
allWorlds = new MultiWorldList(allInstances); //make this be unique pointer or whatever instead of awkward replace and delete iy
|
||||
allWorlds->update();
|
||||
auto newAllWorldsPage = new MultiWorldListPage(allWorlds);
|
||||
ui->horizontalLayout->replaceWidget(allWorldsPage, newAllWorldsPage);
|
||||
delete allWorldsPage;
|
||||
allWorldsPage = newAllWorldsPage;
|
||||
allWorldsList = new MultiWorldList(allInstances);
|
||||
allWorldsList->update();
|
||||
|
||||
allWorldsPage = new MultiWorldListPage(allWorldsList);
|
||||
ui->horizontalLayout->addWidget(allWorldsPage);
|
||||
|
||||
view->setVisible(false);
|
||||
m_oldInstanceToolbarSetting = ui->instanceToolBar->isVisible();
|
||||
|
|
@ -893,16 +882,27 @@ void MainWindow::toggleAllWorldsScreen(bool toggled)
|
|||
allWorldsPage->setVisible(true);
|
||||
statusBar()->setVisible(false);
|
||||
|
||||
allWorlds->startWatching();
|
||||
allWorldsList->startWatching();
|
||||
|
||||
connect(allWorldsPage, &MultiWorldListPage::worldJoined, this, &MainWindow::worldJoined);
|
||||
} else {
|
||||
allWorldsPage->setVisible(false);
|
||||
view->setVisible(true);
|
||||
ui->instanceToolBar->setVisible(m_oldInstanceToolbarSetting);
|
||||
statusBar()->setVisible(APPLICATION->settings()->get("StatusBarVisible").toBool());
|
||||
if (allWorldsList == nullptr || allWorldsPage == nullptr) {
|
||||
view->setVisible(true);
|
||||
ui->instanceToolBar->setVisible(m_oldInstanceToolbarSetting);
|
||||
statusBar()->setVisible(APPLICATION->settings()->get("StatusBarVisible").toBool());
|
||||
} else {
|
||||
allWorldsPage->setVisible(false);
|
||||
view->setVisible(true);
|
||||
ui->instanceToolBar->setVisible(m_oldInstanceToolbarSetting);
|
||||
statusBar()->setVisible(APPLICATION->settings()->get("StatusBarVisible").toBool());
|
||||
|
||||
allWorlds->stopWatching();
|
||||
allWorldsList->stopWatching();
|
||||
|
||||
delete allWorldsList;
|
||||
allWorldsList = nullptr;
|
||||
delete allWorldsPage;
|
||||
allWorldsPage = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ class MainWindow : public QMainWindow {
|
|||
LabeledToolButton* renameButton = nullptr;
|
||||
QToolButton* helpMenuButton = nullptr;
|
||||
KonamiCode* secretEventFilter = nullptr;
|
||||
MultiWorldList* allWorlds = nullptr;
|
||||
MultiWorldList* allWorldsList = nullptr;
|
||||
|
||||
std::shared_ptr<Setting> instanceToolbarSetting = nullptr;
|
||||
bool m_oldInstanceToolbarSetting;
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ void MultiWorldListPage::on_actionCopy_triggered()
|
|||
|
||||
// TODO: Make this a separate dialog class
|
||||
Q_DECLARE_METATYPE(BaseInstance*);
|
||||
MinecraftInstance* MultiWorldListPage::selectInstance(const QString& message, BaseInstance* preselectedInstance)
|
||||
MinecraftInstance* MultiWorldListPage::selectInstance(const QString& message, const BaseInstance* preselectedInstance)
|
||||
{
|
||||
auto *dialog = new QDialog(this);
|
||||
dialog->setWindowTitle(tr("Select Instance"));
|
||||
|
|
@ -475,13 +475,13 @@ MinecraftInstance* MultiWorldListPage::selectInstance(const QString& message, Ba
|
|||
static_cast<int>(std::max(0.75 * window()->height(), 400.0)));
|
||||
dialog->restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get("SelectInstanceGeometry").toByteArray()));
|
||||
|
||||
auto layout = new QVBoxLayout(dialog);
|
||||
auto *layout = new QVBoxLayout(dialog);
|
||||
|
||||
layout->addWidget(new QLabel(message));
|
||||
|
||||
auto instanceList = new QListWidget(dialog);
|
||||
auto *instanceList = new QListWidget(dialog);
|
||||
|
||||
for (auto instance : m_worlds->getInstances()) {
|
||||
for (auto *instance : m_worlds->getInstances()) {
|
||||
auto *item = new QListWidgetItem(instanceList);
|
||||
item->setText(instance->name());
|
||||
item->setIcon(APPLICATION->icons()->getIcon(instance->iconKey()));
|
||||
|
|
@ -495,7 +495,7 @@ MinecraftInstance* MultiWorldListPage::selectInstance(const QString& message, Ba
|
|||
|
||||
layout->addWidget(instanceList);
|
||||
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
|
||||
layout->addWidget(buttonBox);
|
||||
|
|
@ -559,7 +559,7 @@ void MultiWorldListPage::on_actionRefresh_triggered()
|
|||
|
||||
void MultiWorldListPage::worldDoubleClicked(const QModelIndex& index)
|
||||
{
|
||||
auto proxy = (QSortFilterProxyModel*)ui->worldTreeView->model();
|
||||
auto *proxy = static_cast<QSortFilterProxyModel*>(ui->worldTreeView->model());
|
||||
join(proxy->mapToSource(index), LaunchMode::Normal);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class MultiWorldListPage : public QMainWindow, public BasePage {
|
|||
bool worldSafetyNagQuestion(const QString& actionType);
|
||||
void mceditError();
|
||||
void join(const QModelIndex& index, LaunchMode launchMode);
|
||||
MinecraftInstance* selectInstance(const QString& message, BaseInstance* instance = nullptr);
|
||||
MinecraftInstance* selectInstance(const QString& message, const BaseInstance* preselectedInstance = nullptr);
|
||||
|
||||
private:
|
||||
Ui::MultiWorldListPage* ui;
|
||||
|
|
|
|||
|
|
@ -207,13 +207,13 @@ void InstanceView::updateGeometries()
|
|||
viewport()->update();
|
||||
}
|
||||
|
||||
void InstanceView::selectInstance(BaseInstance* instance)
|
||||
void InstanceView::selectInstance(const BaseInstance* instance) const
|
||||
{
|
||||
QModelIndex index;
|
||||
|
||||
for (int row = 0; row < model()->rowCount(); row++) {
|
||||
for (int j = 0; j < model()->columnCount(); j++) {
|
||||
auto testIndex = model()->index(row, j);
|
||||
for (int col = 0; col < model()->columnCount(); col++) {
|
||||
auto testIndex = model()->index(row, col);
|
||||
if (testIndex.data(InstanceList::InstanceIDRole).toString() == instance->id()) {
|
||||
index = testIndex;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class InstanceView : public QAbstractItemView {
|
|||
|
||||
public slots:
|
||||
virtual void updateGeometries() override;
|
||||
void selectInstance(BaseInstance* instance);
|
||||
void selectInstance(const BaseInstance* instance) const;
|
||||
|
||||
protected slots:
|
||||
virtual void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QList<int>& roles) override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue