Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/downloadlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ DownloadList::DownloadList(OrganizerCore& core, QObject* parent)
: QAbstractTableModel(parent), m_manager(*core.downloadManager()),
m_settings(core.settings())
{
connect(&m_manager, SIGNAL(update(int)), this, SLOT(update(int)));
connect(&m_manager, SIGNAL(aboutToUpdate()), this, SLOT(aboutToUpdate()));
connect(&m_manager, &DownloadManager::aboutToResetModel, this,
&DownloadList::onAboutToResetModel);
connect(&m_manager, &DownloadManager::modelReset, this, &DownloadList::onModelReset);
connect(&m_manager, &DownloadManager::rowChanged, this, &DownloadList::onRowChanged);
}

int DownloadList::rowCount(const QModelIndex& parent) const
Expand Down Expand Up @@ -239,16 +241,19 @@ QVariant DownloadList::data(const QModelIndex& index, int role) const
return QVariant();
}

void DownloadList::aboutToUpdate()
void DownloadList::onAboutToResetModel()
{
emit beginResetModel();
beginResetModel();
}

void DownloadList::update(int row)
void DownloadList::onModelReset()
{
if (row < 0)
emit endResetModel();
else if (row < this->rowCount())
endResetModel();
}

void DownloadList::onRowChanged(int row)
{
if (row < this->rowCount())
emit dataChanged(
this->index(row, 0, QModelIndex()),
this->index(row, this->columnCount(QModelIndex()) - 1, QModelIndex()));
Expand Down
18 changes: 11 additions & 7 deletions src/downloadlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,20 @@ class DownloadList : public QAbstractTableModel
//
bool lessThanPredicate(const QModelIndex& left, const QModelIndex& right);

public slots:
private slots:

/**
* @brief used to inform the model that data has changed
*
* @param row the row that changed. This can be negative to update the whole view
**/
void update(int row);
* @brief full reset (row count changed). Drops selection and scroll state.
*/
void onAboutToResetModel();
void onModelReset();

void aboutToUpdate();
/**
* @brief single-row data change (row count unchanged). Preserves view state.
*
* @param row the row that changed
*/
void onRowChanged(int row);

private:
DownloadManager& m_manager;
Expand Down
Loading
Loading