From 50809e7a7cceed1927c2a8f2a95b71ace0f41ab2 Mon Sep 17 00:00:00 2001 From: Rafael Date: Sun, 3 Apr 2016 03:56:24 +0200 Subject: [PATCH] selection bugs at import and delete fixed --- ProfileInterface.cpp | 31 +++++++++++++++++++------------ ProfileWidget.cpp | 10 ++++++++++ ProfileWidget.h | 2 ++ SavegameWidget.cpp | 10 ++++++++++ SavegameWidget.h | 2 ++ SnapmaticWidget.cpp | 10 ++++++++++ SnapmaticWidget.h | 2 ++ 7 files changed, 55 insertions(+), 12 deletions(-) diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index 0ee881a..7a06cc6 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -58,8 +58,15 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre ProfileInterface::~ProfileInterface() { + foreach(ProfileWidget *widget, widgets.keys()) + { + widgets.remove(widget); + widget->deleteLater(); + delete widget; + } foreach(SavegameData *savegame, savegames) { + savegames.removeAll(savegame); savegame->deleteLater(); delete savegame; } @@ -69,12 +76,6 @@ ProfileInterface::~ProfileInterface() picture->deleteLater(); delete picture; } - foreach(ProfileWidget *widget, widgets.keys()) - { - widgets.remove(widget); - widget->deleteLater(); - delete widget; - } profileLoader->deleteLater(); delete profileLoader; delete ui; @@ -104,6 +105,7 @@ void ProfileInterface::on_savegameLoaded(SavegameData *savegame, QString savegam ui->vlSavegame->addWidget(sgdWidget); widgets[sgdWidget] = "SavegameWidget"; savegames.append(savegame); + if (selectedWidgts != 0) { sgdWidget->setSelectionMode(true); } QObject::connect(sgdWidget, SIGNAL(savegameDeleted()), this, SLOT(on_savegameDeleted())); QObject::connect(sgdWidget, SIGNAL(widgetSelected()), this, SLOT(on_profileWidgetSelected())); QObject::connect(sgdWidget, SIGNAL(widgetDeselected()), this, SLOT(on_profileWidgetDeselected())); @@ -116,6 +118,7 @@ void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString pictu ui->vlSnapmatic->addWidget(picWidget); widgets[picWidget] = "SnapmaticWidget"; pictures.append(picture); + if (selectedWidgts != 0) { picWidget->setSelectionMode(true); } QObject::connect(picWidget, SIGNAL(pictureDeleted()), this, SLOT(on_pictureDeleted())); QObject::connect(picWidget, SIGNAL(widgetSelected()), this, SLOT(on_profileWidgetSelected())); QObject::connect(picWidget, SIGNAL(widgetDeselected()), this, SLOT(on_profileWidgetDeselected())); @@ -140,17 +143,21 @@ void ProfileInterface::on_profileLoaded() void ProfileInterface::on_savegameDeleted() { SavegameWidget *sgdWidget = (SavegameWidget*)sender(); - widgets.remove(sgdWidget); - sgdWidget->deleteLater(); - delete sgdWidget; + SavegameData *savegame = sgdWidget->getSavegame(); + if (sgdWidget->isSelected()) { sgdWidget->setChecked(false); } + sgdWidget->close(); + savegames.removeAll(savegame); + delete savegame; } void ProfileInterface::on_pictureDeleted() { SnapmaticWidget *picWidget = (SnapmaticWidget*)sender(); - widgets.remove(picWidget); - picWidget->deleteLater(); - delete picWidget; + SnapmaticPicture *picture = picWidget->getPicture(); + if (picWidget->isSelected()) { picWidget->setChecked(false); } + picWidget->close(); + pictures.removeAll(picture); + delete picture; } void ProfileInterface::on_cmdCloseProfile_clicked() diff --git a/ProfileWidget.cpp b/ProfileWidget.cpp index 6046640..98f42ac 100755 --- a/ProfileWidget.cpp +++ b/ProfileWidget.cpp @@ -24,6 +24,16 @@ ProfileWidget::ProfileWidget(QWidget *parent) : QWidget(parent) } +ProfileWidget::~ProfileWidget() +{ +} + +bool ProfileWidget::isSelected() +{ + qDebug() << "ProfileWidget got used without overwrite"; + return false; +} + void ProfileWidget::setSelectionMode(bool selectionMode) { qDebug() << "ProfileWidget got used without overwrite, result:" << selectionMode; diff --git a/ProfileWidget.h b/ProfileWidget.h index ebdbd0d..c8c6cd6 100755 --- a/ProfileWidget.h +++ b/ProfileWidget.h @@ -27,6 +27,8 @@ class ProfileWidget : public QWidget public: explicit ProfileWidget(QWidget *parent = 0); virtual void setSelectionMode(bool selectionMode); + virtual bool isSelected(); + ~ProfileWidget(); signals: diff --git a/SavegameWidget.cpp b/SavegameWidget.cpp index aec6deb..f996a30 100755 --- a/SavegameWidget.cpp +++ b/SavegameWidget.cpp @@ -141,7 +141,17 @@ void SavegameWidget::on_cbSelected_stateChanged(int arg1) } } +bool SavegameWidget::isSelected() +{ + return ui->cbSelected->isChecked(); +} + void SavegameWidget::setSelectionMode(bool selectionMode) { ui->cbSelected->setVisible(selectionMode); } + +SavegameData* SavegameWidget::getSavegame() +{ + return sgdata; +} diff --git a/SavegameWidget.h b/SavegameWidget.h index 81a72cf..277d109 100755 --- a/SavegameWidget.h +++ b/SavegameWidget.h @@ -38,6 +38,8 @@ public: void setSavegameData(SavegameData *savegame, QString savegamePath); void setSelectionMode(bool selectionMode); void setChecked(bool isChecked); + SavegameData* getSavegame(); + bool isSelected(); ~SavegameWidget(); private slots: diff --git a/SnapmaticWidget.cpp b/SnapmaticWidget.cpp index b2cba48..1688be3 100755 --- a/SnapmaticWidget.cpp +++ b/SnapmaticWidget.cpp @@ -155,7 +155,17 @@ void SnapmaticWidget::on_cbSelected_stateChanged(int arg1) } } +bool SnapmaticWidget::isSelected() +{ + return ui->cbSelected->isChecked(); +} + void SnapmaticWidget::setSelectionMode(bool selectionMode) { ui->cbSelected->setVisible(selectionMode); } + +SnapmaticPicture* SnapmaticWidget::getPicture() +{ + return smpic; +} diff --git a/SnapmaticWidget.h b/SnapmaticWidget.h index 5cc3b62..fe5b064 100755 --- a/SnapmaticWidget.h +++ b/SnapmaticWidget.h @@ -40,6 +40,8 @@ public: void setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath); void setSelectionMode(bool selectionMode); void setChecked(bool isChecked); + bool isSelected(); + SnapmaticPicture *getPicture(); ~SnapmaticWidget(); private slots: