Convert to use private pointer for ui object

This commit is contained in:
Chocobo1 2019-02-25 00:31:39 +08:00
parent bb041c0eca
commit e5dca50025
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
8 changed files with 88 additions and 57 deletions

View file

@ -40,22 +40,24 @@
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "previewlistdelegate.h"
#include "ui_previewselectdialog.h"
#include "utils.h"
#define SETTINGS_KEY(name) "PreviewSelectDialog/" name
PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHandle *const torrent)
: QDialog(parent)
, m_ui(new Ui::PreviewSelectDialog)
, m_torrent(torrent)
, m_storeDialogSize(SETTINGS_KEY("Dimension"))
, m_storeTreeHeaderState(SETTINGS_KEY("HeaderState"))
{
setupUi(this);
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Preview"));
connect(buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelectDialog::previewButtonClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Preview"));
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &PreviewSelectDialog::previewButtonClicked);
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
Preferences *const pref = Preferences::instance();
// Preview list
@ -67,15 +69,15 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
// This hack fixes reordering of first column with Qt5.
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused;
unused.setVerticalHeader(previewList->header());
previewList->header()->setParent(previewList);
unused.setVerticalHeader(m_ui->previewList->header());
m_ui->previewList->header()->setParent(m_ui->previewList);
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
previewList->setModel(m_previewListModel);
previewList->hideColumn(FILE_INDEX);
m_ui->previewList->setModel(m_previewListModel);
m_ui->previewList->hideColumn(FILE_INDEX);
m_listDelegate = new PreviewListDelegate(this);
previewList->setItemDelegate(m_listDelegate);
previewList->setAlternatingRowColors(pref->useAlternatingRowColors());
m_ui->previewList->setItemDelegate(m_listDelegate);
m_ui->previewList->setAlternatingRowColors(pref->useAlternatingRowColors());
// Fill list in
QVector<qreal> fp = torrent->filesProgress();
int nbFiles = torrent->filesCount();
@ -96,8 +98,8 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan
connect(this, SIGNAL(readyToPreviewFile(QString)), parent, SLOT(previewFile(QString)));
m_previewListModel->sort(NAME);
previewList->header()->setSortIndicator(0, Qt::AscendingOrder);
previewList->selectionModel()->select(m_previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows);
m_ui->previewList->header()->setSortIndicator(0, Qt::AscendingOrder);
m_ui->previewList->selectionModel()->select(m_previewListModel->index(0, NAME), QItemSelectionModel::Select | QItemSelectionModel::Rows);
// Restore dialog state
loadWindowState();
@ -119,11 +121,12 @@ PreviewSelectDialog::~PreviewSelectDialog()
delete m_previewListModel;
delete m_listDelegate;
delete m_ui;
}
void PreviewSelectDialog::previewButtonClicked()
{
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX);
QModelIndexList selectedIndexes = m_ui->previewList->selectionModel()->selectedRows(FILE_INDEX);
if (selectedIndexes.isEmpty()) return;
// Flush data
@ -146,7 +149,7 @@ void PreviewSelectDialog::saveWindowState()
// Persist dialog size
m_storeDialogSize = size();
// Persist TreeView Header state
m_storeTreeHeaderState = previewList->header()->saveState();
m_storeTreeHeaderState = m_ui->previewList->header()->saveState();
}
void PreviewSelectDialog::loadWindowState()
@ -156,7 +159,7 @@ void PreviewSelectDialog::loadWindowState()
// Restore TreeView Header state
if (!m_storeTreeHeaderState.value().isEmpty()) {
m_headerStateInitialized = previewList->header()->restoreState(m_storeTreeHeaderState);
m_headerStateInitialized = m_ui->previewList->header()->restoreState(m_storeTreeHeaderState);
}
}
@ -167,8 +170,8 @@ void PreviewSelectDialog::showEvent(QShowEvent *event)
// Default size, have to be called after show(), because width is needed
// Set Name column width to 60% of TreeView
if (!m_headerStateInitialized) {
int nameSize = (previewList->size().width() * 0.6);
previewList->header()->resizeSection(0, nameSize);
int nameSize = (m_ui->previewList->size().width() * 0.6);
m_ui->previewList->header()->resizeSection(0, nameSize);
m_headerStateInitialized = true;
}
}