forked from openkylin/qt5-ukui-platformtheme
messagebox、filedialog内存泄露部分正常析构
This commit is contained in:
parent
034adc52f0
commit
e59dbf83ac
|
@ -345,7 +345,7 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent)
|
|||
onSwitchView();
|
||||
isTableModel();
|
||||
|
||||
m_model = new QStringListModel();
|
||||
m_model = new QStringListModel(this);
|
||||
m_completer = new QCompleter(mKyFileDialogUi->m_fileNameEdit);
|
||||
m_completer->setModel(m_model);
|
||||
m_completer->setMaxVisibleItems(10);
|
||||
|
|
|
@ -37,6 +37,14 @@ KyNativeFileDialogPrivate::KyNativeFileDialogPrivate()
|
|||
// m_container = q->m_container;
|
||||
}
|
||||
|
||||
KyNativeFileDialogPrivate::~KyNativeFileDialogPrivate()
|
||||
{
|
||||
if(m_timer){
|
||||
delete m_timer;
|
||||
m_timer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList KyNativeFileDialogPrivate::typedFiles()
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -36,9 +36,11 @@ class KyFileDialogHelper;
|
|||
class KyNativeFileDialogPrivate
|
||||
{
|
||||
friend class KyNativeFileDialog;
|
||||
private:
|
||||
public:
|
||||
KyNativeFileDialogPrivate();
|
||||
~KyNativeFileDialogPrivate();
|
||||
|
||||
private:
|
||||
QStringList typedFiles();
|
||||
|
||||
QStringList nameFilters;
|
||||
|
|
|
@ -114,8 +114,8 @@ FileDialogSideBar::FileDialogSideBar(QWidget *parent) : QTreeView(parent)
|
|||
setAutoScrollMargin(0);
|
||||
|
||||
|
||||
auto delegate = new SideBarItemDelegate(this);
|
||||
setItemDelegate(delegate);
|
||||
m_delegate = new SideBarItemDelegate(this);
|
||||
setItemDelegate(m_delegate);
|
||||
|
||||
m_model = new Peony::SideBarModel(this);
|
||||
m_proxyModel = new Peony::SideBarProxyFilterSortModel(this);
|
||||
|
@ -244,10 +244,18 @@ FileDialogSideBar::FileDialogSideBar(QWidget *parent) : QTreeView(parent)
|
|||
|
||||
FileDialogSideBar::~FileDialogSideBar()
|
||||
{
|
||||
m_proxyModel->deleteLater();
|
||||
m_proxyModel = nullptr;
|
||||
m_model->deleteLater();
|
||||
m_model = nullptr;
|
||||
if(m_proxyModel){
|
||||
m_proxyModel->deleteLater();
|
||||
m_proxyModel = nullptr;
|
||||
}
|
||||
if(m_model){
|
||||
m_model->deleteLater();
|
||||
m_model = nullptr;
|
||||
}
|
||||
if(m_delegate){
|
||||
m_delegate->deleteLater();
|
||||
m_delegate = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void FileDialogSideBar::tableModeChanged(bool isTableMode)
|
||||
|
|
|
@ -56,6 +56,16 @@ private:
|
|||
QSize m_minSize;
|
||||
};
|
||||
|
||||
class SideBarItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
friend class FileDialogSideBar;
|
||||
explicit SideBarItemDelegate(QObject *parent = nullptr);
|
||||
~SideBarItemDelegate(){}
|
||||
|
||||
// QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
|
||||
class FileDialogSideBar : public QTreeView
|
||||
{
|
||||
|
@ -74,6 +84,7 @@ public Q_SLOTS:
|
|||
private:
|
||||
Peony::SideBarProxyFilterSortModel *m_proxyModel = nullptr;
|
||||
Peony::SideBarModel *m_model = nullptr;
|
||||
SideBarItemDelegate *m_delegate = nullptr;
|
||||
|
||||
Q_SIGNALS:
|
||||
void goToUriRequest(const QString &uri, bool addToHistory = true, bool forceUpdate = false);
|
||||
|
@ -81,17 +92,6 @@ Q_SIGNALS:
|
|||
};
|
||||
|
||||
|
||||
class SideBarItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
friend class FileDialogSideBar;
|
||||
explicit SideBarItemDelegate(QObject *parent = nullptr);
|
||||
~SideBarItemDelegate(){}
|
||||
|
||||
// QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
|
||||
class SideBarStyle : public QProxyStyle
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -78,7 +78,7 @@ MessageBox::MessageBox(QWidget *parent) : QDialog(*new MessageBoxPrivate, parent
|
|||
Q_D(MessageBox);
|
||||
|
||||
const QString locale = QLocale::system().name();
|
||||
QTranslator *translator = new QTranslator();
|
||||
QTranslator *translator = new QTranslator(this);
|
||||
if (translator->load("/usr/share/qt5-ukui-platformtheme/qt5-ukui-platformtheme_" + locale)) {
|
||||
|
||||
//Fix:BUG176598,block QMessagebox translation for xca before commit patch to upstream
|
||||
|
@ -1292,7 +1292,10 @@ MessageBoxHelper::MessageBoxHelper() : QPlatformMessageDialogHelper(), mMessageB
|
|||
|
||||
MessageBoxHelper::~MessageBoxHelper()
|
||||
{
|
||||
|
||||
if(mMessageBox){
|
||||
mMessageBox->deleteLater();
|
||||
mMessageBox = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void MessageBoxHelper::exec()
|
||||
|
@ -1314,7 +1317,7 @@ bool MessageBoxHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wind
|
|||
{
|
||||
initDialog(windowFlags, windowModality, parent);
|
||||
|
||||
if (parent) {
|
||||
if (parent && mMessageBox->find(parent->winId())) {
|
||||
if (QWidget *p = mMessageBox->find(parent->winId())) {
|
||||
for(QMessageBox *mb : p->findChildren<QMessageBox *>())
|
||||
{
|
||||
|
@ -1356,6 +1359,9 @@ bool MessageBoxHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wind
|
|||
for (QMessageBox *mb : p->findChildren<QMessageBox *>()) {
|
||||
if (mb->icon() == options()->icon() && mb->windowTitle() == options()->windowTitle() && mb->text() == options()->text()
|
||||
&& mb->informativeText() == options()->informativeText() && mb->detailedText() == options()->detailedText()) {
|
||||
if(mb->escapeButton() && mMessageBox->escapeButton() != mb->escapeButton())
|
||||
mMessageBox->setEscapeButton(mb->escapeButton());
|
||||
|
||||
if(mb->defaultButton()){
|
||||
QString btnText = mb->defaultButton()->text();
|
||||
foreach (QAbstractButton* btn, mMessageBox->buttons()) {
|
||||
|
@ -1385,13 +1391,16 @@ bool MessageBoxHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality wind
|
|||
mMessageBox->setWindowFlag(Qt::Dialog);
|
||||
}
|
||||
|
||||
if(parent == nullptr)
|
||||
if(parent == nullptr || mMessageBox->find(parent->winId()) == nullptr)
|
||||
{
|
||||
QList<QWidget *> widgets = QApplication::allWidgets();
|
||||
foreach (QWidget *w, widgets) {
|
||||
if(QMessageBox *mb = qobject_cast<QMessageBox *>(w)) {
|
||||
if (mb->icon() == options()->icon() && mb->windowTitle() == options()->windowTitle() && mb->text() == options()->text()
|
||||
&& mb->informativeText() == options()->informativeText() && mb->detailedText() == options()->detailedText()) {
|
||||
if(mb->escapeButton() && mMessageBox->escapeButton() != mb->escapeButton())
|
||||
mMessageBox->setEscapeButton(mb->escapeButton());
|
||||
|
||||
if(mb->defaultButton() == nullptr)
|
||||
break;
|
||||
QString btnText = mb->defaultButton()->text();
|
||||
|
|
Loading…
Reference in New Issue