qol work on discovery dialog!
This commit is contained in:
parent
5238c7e417
commit
26c9d619d7
@ -26,6 +26,8 @@ void AccountCheckModel::setRootItem(RootItem* root_item, bool delete_previous_ro
|
||||
emit layoutAboutToBeChanged();
|
||||
}
|
||||
|
||||
beginResetModel();
|
||||
|
||||
if (delete_previous_root && m_rootItem != nullptr) {
|
||||
m_rootItem->deleteLater();
|
||||
}
|
||||
@ -33,6 +35,8 @@ void AccountCheckModel::setRootItem(RootItem* root_item, bool delete_previous_ro
|
||||
m_checkStates.clear();
|
||||
m_rootItem = root_item;
|
||||
|
||||
endResetModel();
|
||||
|
||||
if (with_layout_change) {
|
||||
emit layoutChanged();
|
||||
}
|
||||
@ -64,7 +68,7 @@ void AccountCheckModel::uncheckAllItems() {
|
||||
|
||||
QModelIndex AccountCheckModel::index(int row, int column, const QModelIndex& parent) const {
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return QModelIndex();
|
||||
return {};
|
||||
}
|
||||
|
||||
RootItem* parent_item = itemForIndex(parent);
|
||||
@ -74,7 +78,7 @@ QModelIndex AccountCheckModel::index(int row, int column, const QModelIndex& par
|
||||
return createIndex(row, column, child_item);
|
||||
}
|
||||
else {
|
||||
return QModelIndex();
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,14 +125,14 @@ QModelIndex AccountCheckModel::indexForItem(RootItem* item) const {
|
||||
|
||||
QModelIndex AccountCheckModel::parent(const QModelIndex& child) const {
|
||||
if (!child.isValid()) {
|
||||
return QModelIndex();
|
||||
return {};
|
||||
}
|
||||
|
||||
RootItem* child_item = itemForIndex(child);
|
||||
RootItem* parent_item = child_item->parent();
|
||||
|
||||
if (parent_item == m_rootItem) {
|
||||
return QModelIndex();
|
||||
if (parent_item == m_rootItem || parent_item == nullptr) {
|
||||
return {};
|
||||
}
|
||||
else {
|
||||
return createIndex(parent_item->row(), 0, parent_item);
|
||||
|
@ -47,23 +47,22 @@ FormDiscoverFeeds::FormDiscoverFeeds(ServiceRoot* service_root,
|
||||
connect(m_btnGoAdvanced, &QPushButton::clicked, this, &FormDiscoverFeeds::userWantsAdvanced);
|
||||
connect(m_ui.m_btnDiscover, &QPushButton::clicked, this, &FormDiscoverFeeds::discoverFeeds);
|
||||
|
||||
connect(&m_watcherLookup, &QFutureWatcher<QList<StandardFeed*>>::progressValueChanged, this, [=](int prog) {
|
||||
m_ui.m_pbDiscovery->setValue(prog);
|
||||
qDebugNN << "progress";
|
||||
});
|
||||
connect(&m_watcherLookup,
|
||||
&QFutureWatcher<QList<StandardFeed*>>::progressValueChanged,
|
||||
this,
|
||||
&FormDiscoverFeeds::onDiscoveryProgress);
|
||||
|
||||
connect(&m_watcherLookup, &QFutureWatcher<QList<StandardFeed*>>::finished, this, [=]() {
|
||||
auto res = m_watcherLookup.future().result();
|
||||
|
||||
loadDiscoveredFeeds(res);
|
||||
});
|
||||
connect(&m_watcherLookup,
|
||||
&QFutureWatcher<QList<StandardFeed*>>::finished,
|
||||
this,
|
||||
&FormDiscoverFeeds::onDiscoveryFinished);
|
||||
|
||||
loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot);
|
||||
|
||||
m_ui.m_tvFeeds->setModel(m_discoveredModel);
|
||||
|
||||
m_ui.m_tvFeeds->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::Stretch);
|
||||
m_ui.m_tvFeeds->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeMode::ResizeToContents);
|
||||
m_ui.m_tvFeeds->header()->setSectionResizeMode(0, QHeaderView::ResizeMode::Stretch);
|
||||
m_ui.m_tvFeeds->header()->setSectionResizeMode(1, QHeaderView::ResizeMode::ResizeToContents);
|
||||
|
||||
m_ui.m_pbDiscovery->setVisible(false);
|
||||
m_ui.m_txtUrl->lineEdit()->setText(url);
|
||||
@ -93,8 +92,27 @@ FormDiscoverFeeds::FormDiscoverFeeds(ServiceRoot* service_root,
|
||||
}
|
||||
}
|
||||
|
||||
void FormDiscoverFeeds::onDiscoveryProgress(int progress) {
|
||||
m_ui.m_pbDiscovery->setValue(progress);
|
||||
}
|
||||
|
||||
void FormDiscoverFeeds::onDiscoveryFinished() {
|
||||
try {
|
||||
auto res = m_watcherLookup.future().result();
|
||||
|
||||
loadDiscoveredFeeds(res);
|
||||
}
|
||||
catch (const ApplicationException& ex) {
|
||||
// TODO: display error
|
||||
}
|
||||
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
FormDiscoverFeeds::~FormDiscoverFeeds() {
|
||||
qDeleteAll(m_parsers);
|
||||
|
||||
m_discoveredModel->setRootItem(nullptr);
|
||||
}
|
||||
|
||||
QList<StandardFeed*> FormDiscoverFeeds::discoverFeedsWithParser(const FeedParser* parser, const QString& url) {
|
||||
@ -137,6 +155,7 @@ void FormDiscoverFeeds::discoverFeeds() {
|
||||
m_ui.m_pbDiscovery->setMaximum(m_parsers.size());
|
||||
m_ui.m_pbDiscovery->setValue(0);
|
||||
m_ui.m_pbDiscovery->setVisible(true);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
void FormDiscoverFeeds::onUrlChanged(const QString& new_url) {
|
||||
@ -175,70 +194,34 @@ void FormDiscoverFeeds::userWantsAdvanced() {
|
||||
}
|
||||
|
||||
void FormDiscoverFeeds::loadDiscoveredFeeds(const QList<StandardFeed*>& feeds) {
|
||||
RootItem* root = new RootItem();
|
||||
|
||||
for (Feed* feed : feeds) {
|
||||
root->appendChild(feed);
|
||||
}
|
||||
|
||||
m_ui.m_pbDiscovery->setVisible(false);
|
||||
m_discoveredModel->setDiscoveredFeeds(feeds);
|
||||
m_discoveredModel->setRootItem(root);
|
||||
|
||||
qDebugNN << "finish";
|
||||
}
|
||||
|
||||
DiscoveredFeedsModel::DiscoveredFeedsModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||
|
||||
int DiscoveredFeedsModel::rowCount(const QModelIndex& parent) const {
|
||||
return m_discoveredFeeds.size();
|
||||
}
|
||||
DiscoveredFeedsModel::DiscoveredFeedsModel(QObject* parent) : AccountCheckModel(parent) {}
|
||||
|
||||
int DiscoveredFeedsModel::columnCount(const QModelIndex& parent) const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant DiscoveredFeedsModel::data(const QModelIndex& index, int role) const {
|
||||
switch (role) {
|
||||
case Qt::ItemDataRole::DisplayRole: {
|
||||
if (index.column() == 0) {
|
||||
return m_discoveredFeeds.at(index.row()).m_feed->title();
|
||||
}
|
||||
else {
|
||||
return StandardFeed::typeToString(m_discoveredFeeds.at(index.row()).m_feed->type());
|
||||
}
|
||||
if (role == Qt::ItemDataRole::DisplayRole && index.column() == 1) {
|
||||
StandardFeed* fd = qobject_cast<StandardFeed*>(itemForIndex(index));
|
||||
|
||||
if (fd != nullptr) {
|
||||
return StandardFeed::typeToString(fd->type());
|
||||
}
|
||||
|
||||
case Qt::ItemDataRole::CheckStateRole: {
|
||||
if (index.column() == 0) {
|
||||
return m_discoveredFeeds.at(index.row()).m_isChecked ? Qt::CheckState::Checked : Qt::CheckState::Unchecked;
|
||||
}
|
||||
else {
|
||||
return {};
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::ItemDataRole::DecorationRole: {
|
||||
if (index.column() == 0) {
|
||||
return m_discoveredFeeds.at(index.row()).m_feed->fullIcon();
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
QList<DiscoveredFeedsModel::FeedItem> DiscoveredFeedsModel::discoveredFeeds() const {
|
||||
return m_discoveredFeeds;
|
||||
}
|
||||
|
||||
void DiscoveredFeedsModel::setDiscoveredFeeds(const QList<StandardFeed*>& feeds) {
|
||||
auto std_feeds = boolinq::from(feeds)
|
||||
.select([](StandardFeed* fd) {
|
||||
return FeedItem{false, fd};
|
||||
})
|
||||
.toStdList();
|
||||
|
||||
m_discoveredFeeds = FROM_STD_LIST(QList<FeedItem>, std_feeds);
|
||||
|
||||
emit layoutAboutToBeChanged();
|
||||
emit layoutChanged();
|
||||
return AccountCheckModel::data(index, role);
|
||||
}
|
||||
|
||||
QVariant DiscoveredFeedsModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
@ -254,17 +237,3 @@ QVariant DiscoveredFeedsModel::headerData(int section, Qt::Orientation orientati
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Qt::ItemFlags DiscoveredFeedsModel::flags(const QModelIndex& index) const {
|
||||
return index.column() == 0 ? Qt::ItemFlag::ItemIsUserCheckable | QAbstractListModel::flags(index)
|
||||
: QAbstractListModel::flags(index);
|
||||
}
|
||||
|
||||
bool DiscoveredFeedsModel::setData(const QModelIndex& index, const QVariant& value, int role) {
|
||||
if (role == Qt::ItemDataRole::CheckStateRole && index.column() == 0) {
|
||||
m_discoveredFeeds[index.row()].m_isChecked = value.value<Qt::CheckState>() == Qt::CheckState::Checked;
|
||||
return true;
|
||||
}
|
||||
|
||||
return QAbstractListModel::setData(index, value, role);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "ui_formdiscoverfeeds.h"
|
||||
|
||||
#include "services/abstract/accountcheckmodel.h"
|
||||
#include "services/standard/parsers/feedparser.h"
|
||||
|
||||
#include <QFutureWatcher>
|
||||
@ -15,29 +16,15 @@ class ServiceRoot;
|
||||
class RootItem;
|
||||
class Category;
|
||||
|
||||
class DiscoveredFeedsModel : public QAbstractListModel {
|
||||
class DiscoveredFeedsModel : public AccountCheckModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct FeedItem {
|
||||
bool m_isChecked;
|
||||
StandardFeed* m_feed;
|
||||
};
|
||||
|
||||
explicit DiscoveredFeedsModel(QObject* parent = {});
|
||||
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
virtual int rowCount(const QModelIndex& parent) const;
|
||||
virtual int columnCount(const QModelIndex& parent) const;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
|
||||
QList<FeedItem> discoveredFeeds() const;
|
||||
void setDiscoveredFeeds(const QList<StandardFeed*>& feeds);
|
||||
|
||||
private:
|
||||
QList<FeedItem> m_discoveredFeeds;
|
||||
};
|
||||
|
||||
class FormDiscoverFeeds : public QDialog {
|
||||
@ -56,6 +43,9 @@ class FormDiscoverFeeds : public QDialog {
|
||||
void addSingleFeed(StandardFeed* feed);
|
||||
void importSelectedFeeds();
|
||||
|
||||
void onDiscoveryProgress(int progress);
|
||||
void onDiscoveryFinished();
|
||||
|
||||
private:
|
||||
QList<StandardFeed*> discoverFeedsWithParser(const FeedParser* parser, const QString& url);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>513</width>
|
||||
<width>593</width>
|
||||
<height>360</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -45,7 +45,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="m_gbFeeds">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
@ -57,31 +57,6 @@
|
||||
<string>Discovered feeds</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QTableView" name="m_tvFeeds">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="cornerButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderVisible">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="m_lblParentCategory">
|
||||
<property name="text">
|
||||
@ -125,23 +100,38 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QProgressBar" name="m_pbDiscovery">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>5</height>
|
||||
</size>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QTreeView" name="m_tvFeeds">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="textVisible">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="indentation">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="m_buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -151,6 +141,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QProgressBar" name="m_pbDiscovery">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>8</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="textVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
Loading…
x
Reference in New Issue
Block a user