From e8fae17beb4ba9fe5c6979750dc995b40c272868 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Mon, 19 Dec 2022 16:18:18 +0200 Subject: [PATCH] Dont delay widget deletion and cleanup code (#1140) IB-7583 Signed-off-by: Raul Metsma Signed-off-by: Raul Metsma --- client/dialogs/AddRecipients.cpp | 4 ++-- client/widgets/ContainerPage.cpp | 20 ++++++++++---------- client/widgets/ContainerPage.h | 2 +- client/widgets/FileList.cpp | 29 ++++------------------------- client/widgets/FileList.h | 20 ++++++++------------ client/widgets/ItemList.cpp | 29 ++++++++++------------------- client/widgets/ItemList.h | 8 ++++---- 7 files changed, 39 insertions(+), 73 deletions(-) diff --git a/client/dialogs/AddRecipients.cpp b/client/dialogs/AddRecipients.cpp index 206910b57..2daac0bae 100644 --- a/client/dialogs/AddRecipients.cpp +++ b/client/dialogs/AddRecipients.cpp @@ -58,9 +58,9 @@ AddRecipients::AddRecipients(ItemList* itemList, QWidget *parent) setWindowFlags( Qt::Dialog | Qt::CustomizeWindowHint ); new Overlay(this, parent->topLevelWidget()); - ui->leftPane->init(ria::qdigidoc4::ToAddAdresses, QStringLiteral("Add recipients")); + ui->leftPane->init(ria::qdigidoc4::ToAddAdresses, QT_TRANSLATE_NOOP("ItemList", "Add recipients")); ui->leftPane->setFont(Styles::font(Styles::Regular, 20)); - ui->rightPane->init(ria::qdigidoc4::AddedAdresses, QStringLiteral("Added recipients")); + ui->rightPane->init(ria::qdigidoc4::AddedAdresses, QT_TRANSLATE_NOOP("ItemList", "Added recipients")); ui->rightPane->setFont(Styles::font(Styles::Regular, 20)); ui->fromCard->setFont(Styles::font(Styles::Condensed, 12)); diff --git a/client/widgets/ContainerPage.cpp b/client/widgets/ContainerPage.cpp index d0d628749..a55217256 100644 --- a/client/widgets/ContainerPage.cpp +++ b/client/widgets/ContainerPage.cpp @@ -256,7 +256,7 @@ void ContainerPage::setHeader(const QString &file) elideFileName(); } -void ContainerPage::showRightPane(ItemType itemType, const QString &header) +void ContainerPage::showRightPane(ItemType itemType, const char *header) { ui->rightPane->init(itemType, header); ui->rightPane->show(); @@ -323,7 +323,7 @@ void ContainerPage::transition(DigiDoc* container) if(!container->timestamps().isEmpty()) { - ui->rightPane->addHeader(QStringLiteral("Container timestamps")); + ui->rightPane->addHeader(QT_TRANSLATE_NOOP("ItemList", "Container timestamps")); for(const DigiDocSignature &c: container->timestamps()) { @@ -404,7 +404,7 @@ void ContainerPage::updatePanes(ContainerState state) ui->changeLocation->show(); ui->rightPane->clear(); hideRightPane(); - ui->leftPane->init(fileName, QStringLiteral("Container files")); + ui->leftPane->init(fileName, QT_TRANSLATE_NOOP("ItemList", "Container files")); showSigningButton(); setButtonsVisible({ ui->cancel, ui->convert, ui->save }, true); setButtonsVisible({ ui->saveAs, ui->email, ui->summary }, false); @@ -413,20 +413,20 @@ void ContainerPage::updatePanes(ContainerState state) cancelText = QT_TR_NOOP("STARTING"); ui->changeLocation->show(); - ui->leftPane->init(fileName, QStringLiteral("Container files")); + ui->leftPane->init(fileName, QT_TRANSLATE_NOOP("ItemList", "Container files")); if( showPrintSummary ) setButtonsVisible({ ui->cancel, ui->convert, ui->saveAs, ui->email, ui->summary }, true); else setButtonsVisible({ ui->cancel, ui->convert, ui->saveAs, ui->email }, true); setButtonsVisible({ ui->save }, false); - showRightPane( ItemSignature, QStringLiteral("Container is not signed")); + showRightPane( ItemSignature, QT_TRANSLATE_NOOP("ItemList", "Container is not signed")); break; case SignedContainer: cancelText = QT_TR_NOOP("STARTING"); ui->changeLocation->hide(); - ui->leftPane->init(fileName, QStringLiteral("Container files")); - showRightPane(ItemSignature, QStringLiteral("Container signatures")); + ui->leftPane->init(fileName, QT_TRANSLATE_NOOP("ItemList", "Container files")); + showRightPane(ItemSignature, QT_TRANSLATE_NOOP("ItemList", "Container signatures")); if( showPrintSummary ) setButtonsVisible({ ui->cancel, ui->convert, ui->saveAs, ui->email, ui->summary }, true); else @@ -439,7 +439,7 @@ void ContainerPage::updatePanes(ContainerState state) ui->changeLocation->show(); ui->leftPane->init(fileName); - showRightPane(ItemAddress, QStringLiteral("Recipients")); + showRightPane(ItemAddress, QT_TRANSLATE_NOOP("ItemList", "Recipients")); showMainAction({ EncryptContainer }); setButtonsVisible({ ui->cancel, ui->convert }, true); setButtonsVisible({ ui->save, ui->saveAs, ui->email, ui->summary }, false); @@ -449,8 +449,8 @@ void ContainerPage::updatePanes(ContainerState state) convertText = QT_TR_NOOP("SIGN"); ui->changeLocation->hide(); - ui->leftPane->init(fileName, QStringLiteral("Encrypted files")); - showRightPane(ItemAddress, QStringLiteral("Recipients")); + ui->leftPane->init(fileName, QT_TRANSLATE_NOOP("ItemList", "Encrypted files")); + showRightPane(ItemAddress, QT_TRANSLATE_NOOP("ItemList", "Recipients")); updateDecryptionButton(); setButtonsVisible({ ui->save, ui->summary }, false); setButtonsVisible({ ui->cancel, ui->convert, ui->saveAs, ui->email }, true); diff --git a/client/widgets/ContainerPage.h b/client/widgets/ContainerPage.h index 932e2168f..54224549f 100644 --- a/client/widgets/ContainerPage.h +++ b/client/widgets/ContainerPage.h @@ -73,7 +73,7 @@ class ContainerPage final : public QWidget void hideRightPane(); void initContainer( const QString &file, const QString &suffix ); void showMainAction(const QList &actions); - void showRightPane(ria::qdigidoc4::ItemType itemType, const QString &header); + void showRightPane(ria::qdigidoc4::ItemType itemType, const char *header); void showSigningButton(); void updateDecryptionButton(); void updatePanes(ria::qdigidoc4::ContainerState state); diff --git a/client/widgets/FileList.cpp b/client/widgets/FileList.cpp index dd717c867..e72851de6 100644 --- a/client/widgets/FileList.cpp +++ b/client/widgets/FileList.cpp @@ -60,24 +60,12 @@ void FileList::addFile( const QString& file ) updateDownload(); } -void FileList::changeEvent(QEvent* event) -{ - ItemList::changeEvent(event); - if(!ui->count->isHidden()) - ui->count->setText(QString::number(count())); -} - void FileList::clear() { ItemList::clear(); documentModel = nullptr; } -int FileList::count() const -{ - return findChildren().size(); -} - bool FileList::eventFilter(QObject *obj, QEvent *event) { if(!qobject_cast(obj)) @@ -121,7 +109,7 @@ bool FileList::eventFilter(QObject *obj, QEvent *event) return ItemList::eventFilter(obj, event); } -void FileList::init(const QString &container, const QString &label) +void FileList::init(const QString &container, const char *label) { ItemList::init(ItemFile, label); this->container = container; @@ -129,18 +117,10 @@ void FileList::init(const QString &container, const QString &label) void FileList::open(FileItem *item) const { - int i; - if(documentModel && (i = index(item)) != -1) + if(int i = index(item); documentModel && i != -1) documentModel->open(i); } -void FileList::remove(Item *item) -{ - int i; - if(documentModel && (i = index(item)) != -1) - emit removed(i); -} - void FileList::removeItem(int row) { ItemList::removeItem(row); @@ -150,8 +130,7 @@ void FileList::removeItem(int row) void FileList::save(FileItem *item) { - int i; - if(documentModel && (i = index(item)) != -1) + if(int i = index(item); documentModel && i != -1) { QString extension = QFileInfo(item->getFile()).suffix(); QString capitalized = extension[0].toUpper() + extension.mid(1); @@ -247,7 +226,7 @@ void FileList::stateChange(ria::qdigidoc4::ContainerState state) void FileList::updateDownload() { - int c = count(); + int c = findChildren().size(); ui->download->setVisible(state & (UnsignedSavedContainer | SignedContainer | UnencryptedContainer) && c); ui->count->setVisible(state & (UnsignedSavedContainer | SignedContainer | UnencryptedContainer) && c); ui->count->setText(QString::number(c)); diff --git a/client/widgets/FileList.h b/client/widgets/FileList.h index fbe00c64c..ec391ddc2 100644 --- a/client/widgets/FileList.h +++ b/client/widgets/FileList.h @@ -27,7 +27,7 @@ class QLabel; -class FileList : public ItemList +class FileList final : public ItemList { Q_OBJECT @@ -35,26 +35,22 @@ class FileList : public ItemList explicit FileList(QWidget *parent = nullptr); void addFile(const QString& file); - void clear() override; - void init(const QString &container, const QString &label = "Container's files"); - void removeItem(int row) override; + void clear() final; + void init(const QString &container, + const char *label = QT_TRANSLATE_NOOP("ItemList", "Container files")); + void removeItem(int row) final; void setModel(DocumentModel *documentModel); - void stateChange(ria::qdigidoc4::ContainerState state) override; + void stateChange(ria::qdigidoc4::ContainerState state) final; signals: void addFiles(const QStringList &files); -private slots: +private: void open(FileItem *item) const; void save(FileItem *item); void saveAll(); - -private: - void changeEvent(QEvent* event) override; - int count() const; - bool eventFilter(QObject *obj, QEvent *event) override; + bool eventFilter(QObject *obj, QEvent *event) final; void selectFile(); - void remove(Item *item) override; void updateDownload(); QString container; diff --git a/client/widgets/ItemList.cpp b/client/widgets/ItemList.cpp index 67fe26580..f99528d05 100644 --- a/client/widgets/ItemList.cpp +++ b/client/widgets/ItemList.cpp @@ -47,11 +47,11 @@ ItemList::~ItemList() delete ui; } -void ItemList::addHeader(const QString &label) +void ItemList::addHeader(const char *label) { headerText = label; - header = new QLabel(tr(qPrintable(label)), this); + header = new QLabel(tr(label), this); header->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); header->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); header->setFocusPolicy(Qt::TabFocus); @@ -110,22 +110,14 @@ void ItemList::changeEvent(QEvent* event) { if (event->type() == QEvent::LanguageChange) { - tr("Add recipients"); - tr("Added recipients"); - tr("Recipients"); - tr("Encrypted files"); - tr("Container is not signed"); - tr("Container signatures"); - tr("Container timestamps"); - tr("Container files"); ui->retranslateUi(this); - ui->listHeader->setText(tr(qPrintable(listText))); + ui->listHeader->setText(tr(listText)); ui->txtFind->setPlaceholderText(tr("Enter the personal code, institution or registry code")); ui->txtFind->setAccessibleName(ui->txtFind->placeholderText()); if(header) - header->setText(tr(qPrintable(headerText))); + header->setText(tr(headerText)); ui->add->setText(addLabel()); @@ -146,7 +138,7 @@ void ItemList::clear() header = nullptr; for(auto it = items.begin(); it != items.end(); it = items.erase(it)) - (*it)->deleteLater(); + delete *it; } bool ItemList::eventFilter(QObject *o, QEvent *e) @@ -176,11 +168,11 @@ bool ItemList::hasItem(const std::function &cb) return std::any_of(items.cbegin(), items.cend(), cb); } -void ItemList::init(ItemType item, const QString &header) +void ItemList::init(ItemType item, const char *header) { itemType = item; - ui->listHeader->setText(tr(qPrintable(header))); - ui->listHeader->setAccessibleName(tr(qPrintable(header))); + ui->listHeader->setText(tr(header)); + ui->listHeader->setAccessibleName(tr(header)); listText = header; ui->listHeader->setFont( Styles::font(Styles::Regular, 20)); @@ -234,15 +226,14 @@ void ItemList::init(ItemType item, const QString &header) void ItemList::remove(Item *item) { - int i = index(item); - if(i != -1) + if(int i = index(item); i != -1) emit removed(i); } void ItemList::removeItem(int row) { if(row < items.size()) - items.takeAt(row)->deleteLater(); + delete items.takeAt(row); } void ItemList::setRecipientTooltip() diff --git a/client/widgets/ItemList.h b/client/widgets/ItemList.h index 4a08f0a63..b29b2a78a 100644 --- a/client/widgets/ItemList.h +++ b/client/widgets/ItemList.h @@ -42,8 +42,8 @@ class ItemList : public QScrollArea explicit ItemList(QWidget *parent = {}); ~ItemList() override; - void init(ria::qdigidoc4::ItemType itemType, const QString &header); - void addHeader(const QString &label); + void init(ria::qdigidoc4::ItemType itemType, const char *header); + void addHeader(const char *label); void addHeaderWidget(Item *widget); void addWidget(Item *widget); virtual void clear(); @@ -78,8 +78,8 @@ class ItemList : public QScrollArea QList items; QLabel *header = nullptr; ria::qdigidoc4::ItemType itemType = ria::qdigidoc4::ItemAddress; - QString headerText; - QString listText; + const char *headerText = ""; + const char *listText = ""; SslCertificate cert; friend class AddRecipients;