From 4c0d791052b77f10aad4b72799500c0c68bad360 Mon Sep 17 00:00:00 2001 From: iaom <18504285112@163.com> Date: Thu, 25 Mar 2021 10:46:26 +0800 Subject: [PATCH] Optimized some inappropriate code. --- libsearch/appsearch/app-match.cpp | 2 +- src/content-widget.cpp | 6 +++--- src/control/highlight-item-delegate.cpp | 2 +- src/control/highlight-item-delegate.h | 2 +- src/control/search-list-view.cpp | 4 ++-- src/model/search-item-model.cpp | 2 +- src/model/search-item-model.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libsearch/appsearch/app-match.cpp b/libsearch/appsearch/app-match.cpp index 2e541c1..c421dba 100644 --- a/libsearch/appsearch/app-match.cpp +++ b/libsearch/appsearch/app-match.cpp @@ -272,7 +272,7 @@ void AppMatch::appNameMatch(QString appname,QMap &instal installed.insert(name,list); return; } - for(int i;isetSpacing(0); m_homePageLyt->setContentsMargins(0,0,0,0); m_homePage->setLayout(m_homePageLyt); - m_resultPage = new QWidget; + m_resultPage = new QWidget(this); m_resultPageLyt = new QHBoxLayout(m_resultPage); m_resultPageLyt->setSpacing(0); m_resultPageLyt->setContentsMargins(0, 0, 0, 0); @@ -74,7 +74,7 @@ void ContentWidget::initUI() { m_resultPageLyt->addWidget(m_resultDetailArea); m_resultPage->setLayout(m_resultPageLyt); - m_resultList = new QWidget(m_resultDetailArea); + m_resultList = new QWidget(m_resultListArea); m_resultDetail = new QWidget(m_resultDetailArea); m_listLyt = new QVBoxLayout(m_resultList); m_detailLyt = new QVBoxLayout(m_resultDetail); diff --git a/src/control/highlight-item-delegate.cpp b/src/control/highlight-item-delegate.cpp index 3d41e80..9aae3d8 100644 --- a/src/control/highlight-item-delegate.cpp +++ b/src/control/highlight-item-delegate.cpp @@ -26,7 +26,7 @@ #include #include -HighlightItemDelegate::HighlightItemDelegate() +HighlightItemDelegate::HighlightItemDelegate(QObject *parent) : QStyledItemDelegate (parent) { } diff --git a/src/control/highlight-item-delegate.h b/src/control/highlight-item-delegate.h index 86a8ed7..947dd97 100644 --- a/src/control/highlight-item-delegate.h +++ b/src/control/highlight-item-delegate.h @@ -27,7 +27,7 @@ class HighlightItemDelegate : public QStyledItemDelegate { Q_OBJECT public: - explicit HighlightItemDelegate(); + explicit HighlightItemDelegate(QObject *parent = nullptr); void setSearchKeyword(const QString &); private: QString m_regFindKeyWords = 0; diff --git a/src/control/search-list-view.cpp b/src/control/search-list-view.cpp index f1d2b79..45752a6 100644 --- a/src/control/search-list-view.cpp +++ b/src/control/search-list-view.cpp @@ -27,7 +27,7 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::SingleSelection); - m_model = new SearchItemModel; + m_model = new SearchItemModel(this); m_item = new SearchItem; m_item->setSearchList(type, list); m_model->setItem(m_item); @@ -40,7 +40,7 @@ SearchListView::SearchListView(QWidget * parent, const QStringList& list, const this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAutoFillBackground(false); this->setStyleSheet("QWidget{background:transparent;}"); - m_styleDelegate = new HighlightItemDelegate(); + m_styleDelegate = new HighlightItemDelegate(this); // m_styleDelegate->setSearchKeyword(keyword); this->setItemDelegate(m_styleDelegate); diff --git a/src/model/search-item-model.cpp b/src/model/search-item-model.cpp index 90e4e2e..d28c14f 100644 --- a/src/model/search-item-model.cpp +++ b/src/model/search-item-model.cpp @@ -21,7 +21,7 @@ #include "search-item-model.h" #include -SearchItemModel::SearchItemModel() +SearchItemModel::SearchItemModel(QObject *parent) : QAbstractItemModel (parent) { } diff --git a/src/model/search-item-model.h b/src/model/search-item-model.h index 1b6b285..721d0a4 100644 --- a/src/model/search-item-model.h +++ b/src/model/search-item-model.h @@ -32,7 +32,7 @@ class SearchItemModel : public QAbstractItemModel friend class SearchItem; Q_OBJECT public: - explicit SearchItemModel(); + explicit SearchItemModel(QObject *parent = nullptr); ~SearchItemModel(); enum SearchInfo {