Fixed child searching + work on feed adding/editing.

This commit is contained in:
Martin Rotter 2014-01-29 20:29:28 +01:00
parent eba5c29902
commit 95e98c7dac
10 changed files with 106 additions and 42 deletions

View File

@ -94,8 +94,9 @@
#define FDS_DB_CATEGORY_INDEX 5
#define FDS_DB_ENCODING_INDEX 6
#define FDS_DB_URL_INDEX 7
#define FDS_DB_LANGUAGE_INDEX 8
#define FDS_DB_TYPE_INDEX 9
#define FDS_DB_TYPE_INDEX 8
//#define FDS_DB_LANGUAGE_INDEX 8
//#define FDS_DB_TYPE_INDEX 9
// Indexes of columns for feed models.
#define FDS_MODEL_TITLE_INDEX 0

View File

@ -72,16 +72,17 @@ class FeedsModelRootItem {
return m_childItems;
}
// Checks whether this instance is child (can be nested)
// if given root item.
bool isChildOf(FeedsModelRootItem *root) {
// Checks whether THIS object is child (direct or indirect)
// of the given root.
bool isChildOf(FeedsModelRootItem *root) {
FeedsModelRootItem *this_item = this;
while (root->kind() != FeedsModelRootItem::RootItem) {
if (root->childItems().contains(this)) {
while (this_item->kind() != FeedsModelRootItem::RootItem) {
if (root->childItems().contains(this_item)) {
return true;
}
else {
root = root->parent();
this_item = this_item->parent();
}
}

View File

@ -32,7 +32,6 @@ FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord
feed->setIcon(IconFactory::fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
feed->setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString());
feed->setUrl(record.value(FDS_DB_URL_INDEX).toString());
feed->setLanguage(record.value(FDS_DB_LANGUAGE_INDEX).toString());
feed->updateCounts();
return feed;
@ -74,14 +73,11 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const {
if (column == FDS_MODEL_TITLE_INDEX) {
return QObject::tr("%1 (%2)\n"
"%3\n\n"
"Encoding: %4\n"
"Language: %5").arg(m_title,
"Encoding: %4").arg(m_title,
FeedsModelFeed::typeToString(m_type),
m_description,
m_encoding,
m_language.isEmpty() ?
"-" :
m_language); }
m_encoding);
}
else if (column == FDS_MODEL_COUNTS_INDEX) {
return QObject::tr("%n unread message(s).", "", countOfUnreadMessages());
}

View File

@ -45,14 +45,6 @@ class FeedsModelStandardFeed : public FeedsModelFeed {
m_url = url;
}
inline QString language() const {
return m_language;
}
inline void setLanguage(const QString &language) {
m_language = language;
}
// Loads standard feed object from given SQL record.
static FeedsModelStandardFeed *loadFromRecord(const QSqlRecord &record);
@ -65,7 +57,6 @@ class FeedsModelStandardFeed : public FeedsModelFeed {
private:
QString m_encoding;
QString m_url;
QString m_language;
};
#endif // FEEDSMODELSTANDARDFEED_H

View File

@ -7,6 +7,7 @@
#include "core/feedsproxymodel.h"
#include "core/feedsmodelrootitem.h"
#include "core/feedsmodelcategory.h"
#include "core/feedsmodelstandardfeed.h"
#include "core/feedsmodelstandardcategory.h"
#include "gui/formmain.h"
#include "gui/formstandardcategorydetails.h"
@ -111,10 +112,9 @@ void FeedsView::addNewStandardCategory() {
}
void FeedsView::editStandardCategory(FeedsModelStandardCategory *category) {
FeedsModelStandardCategory *std_category = static_cast<FeedsModelStandardCategory*>(category);
QPointer<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(m_sourceModel, this);
if (form_pointer.data()->exec(std_category) == QDialog::Accepted) {
if (form_pointer.data()->exec(category) == QDialog::Accepted) {
// TODO: kategorie upravena
}
else {
@ -160,6 +160,19 @@ void FeedsView::addNewStandardFeed() {
SystemFactory::instance()->applicationCloseLock()->unlock();
}
void FeedsView::editStandardFeed(FeedsModelStandardFeed *feed) {
QPointer<FormStandardFeedDetails> form_pointer = new FormStandardFeedDetails(m_sourceModel, this);
if (form_pointer.data()->exec(feed) == QDialog::Accepted) {
// TODO: kategorie upravena
}
else {
// TODO: kategorie neupravena (uživatel zrušil dialog)
}
delete form_pointer.data();
}
void FeedsView::editSelectedItem() {
if (!SystemFactory::instance()->applicationCloseLock()->tryLockForWrite()) {
// Lock was not obtained because
@ -199,6 +212,19 @@ void FeedsView::editSelectedItem() {
}
else if ((feed = isCurrentIndexFeed()) != NULL) {
// Feed is selected.
switch (feed->type()) {
case FeedsModelFeed::StandardAtom10:
case FeedsModelFeed::StandardRdf:
case FeedsModelFeed::StandardRss0X:
case FeedsModelFeed::StandardRss2X: {
// User wants to edit standard feed.
editStandardFeed(static_cast<FeedsModelStandardFeed*>(feed));
break;
}
default:
break;
}
}
// Changes are done, unlock the update master lock.

View File

@ -78,6 +78,7 @@ class FeedsView : public QTreeView {
// Standard feed manipulators.
void addNewStandardFeed();
void editStandardFeed(FeedsModelStandardFeed *feed);
// Reloads counts for selected feeds.
void updateCountsOfSelectedFeeds(bool update_total_too = true);

View File

@ -65,6 +65,11 @@ void FormStandardCategoryDetails::setEditableCategory(FeedsModelStandardCategory
}
int FormStandardCategoryDetails::exec(FeedsModelStandardCategory *input_category) {
// Load categories.
loadCategories(m_feedsModel->allCategories().values(),
m_feedsModel->rootItem(),
input_category);
if (input_category == NULL) {
// User is adding new category.
setWindowTitle(tr("Add new standard category"));
@ -79,11 +84,6 @@ int FormStandardCategoryDetails::exec(FeedsModelStandardCategory *input_category
setEditableCategory(input_category);
}
// Load categories.
loadCategories(m_feedsModel->allCategories().values(),
m_feedsModel->rootItem(),
input_category);
// Run the dialog.
return QDialog::exec();
}
@ -211,7 +211,6 @@ void FormStandardCategoryDetails::loadCategories(const QList<FeedsModelCategory*
foreach (FeedsModelCategory *category, categories) {
if (input_category != NULL && (category == input_category ||
input_category->parent() == category ||
category->isChildOf(input_category))) {
// This category cannot be selected as the new
// parent for currently edited category, so

View File

@ -2,9 +2,12 @@
#include "core/textfactory.h"
#include "core/feedsmodel.h"
#include "core/feedsmodelrootitem.h"
#include "core/feedsmodelcategory.h"
#include "core/feedsmodelfeed.h"
#include "core/feedsmodelstandardfeed.h"
#include "gui/iconthemefactory.h"
#include "gui/baselineedit.h"
#if !defined(Q_OS_WIN)
#include "gui/messagebox.h"
@ -15,7 +18,9 @@
FormStandardFeedDetails::FormStandardFeedDetails(FeedsModel *model, QWidget *parent)
: QDialog(parent) {
: QDialog(parent),
m_editableFeed(NULL),
m_feedsModel(model) {
initialize();
}
@ -24,6 +29,11 @@ FormStandardFeedDetails::~FormStandardFeedDetails() {
}
int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) {
// Load categories.
loadCategories(m_feedsModel->allCategories().values(),
m_feedsModel->rootItem(),
input_feed);
if (input_feed == NULL) {
// User is adding new category.
setWindowTitle(tr("Add new standard feed"));
@ -31,15 +41,25 @@ int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) {
else {
// User is editing existing category.
setWindowTitle(tr("Edit existing standard feed"));
// TODO: set editable feed.
setEditableFeed(input_feed);
}
// TODO: Load categories.
// Run the dialog.
return QDialog::exec();
}
void FormStandardFeedDetails::setEditableFeed(FeedsModelStandardFeed *editable_feed) {
m_editableFeed = editable_feed;
m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) editable_feed->parent())));
m_ui->m_txtTitle->lineEdit()->setText(editable_feed->title());
m_ui->m_txtDescription->lineEdit()->setText(editable_feed->description());
m_ui->m_btnIcon->setIcon(editable_feed->icon());
m_ui->m_cmbType->setCurrentIndex(m_ui->m_cmbType->findData(QVariant::fromValue((void*) editable_feed->type())));
m_ui->m_cmbEncoding->setCurrentIndex(m_ui->m_cmbEncoding->findData(editable_feed->encoding(), Qt::DisplayRole));
m_ui->m_txtUrl->lineEdit()->setText(editable_feed->url());
}
void FormStandardFeedDetails::initialize() {
m_ui = new Ui::FormStandardFeedDetails();
m_ui->setupUi(this);
@ -56,10 +76,10 @@ void FormStandardFeedDetails::initialize() {
#endif
// Add standard feed types.
m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardAtom10), QVariant::fromValue(FeedsModelFeed::StandardAtom10));
m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRdf), QVariant::fromValue(FeedsModelFeed::StandardRdf));
m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss0X), QVariant::fromValue(FeedsModelFeed::StandardRss0X));
m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss2X), QVariant::fromValue(FeedsModelFeed::StandardRss2X));
m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardAtom10), QVariant::fromValue((void*) FeedsModelFeed::StandardAtom10));
m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRdf), QVariant::fromValue((void*) FeedsModelFeed::StandardRdf));
m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss0X), QVariant::fromValue((void*) FeedsModelFeed::StandardRss0X));
m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss2X), QVariant::fromValue((void*) FeedsModelFeed::StandardRss2X));
// Load available encodings.
QList<QByteArray> encodings = QTextCodec::availableCodecs();
@ -71,5 +91,19 @@ void FormStandardFeedDetails::initialize() {
qSort(encoded_encodings.begin(), encoded_encodings.end(), TextFactory::isCaseInsensitiveLessThan);
m_ui->m_cmbEncoding->addItems(encoded_encodings);
}
void FormStandardFeedDetails::loadCategories(const QList<FeedsModelCategory*> categories,
FeedsModelRootItem *root_item,
FeedsModelStandardFeed *input_feed) {
m_ui->m_cmbParentCategory->addItem(root_item->icon(),
root_item->title(),
QVariant::fromValue((void*) root_item));
foreach (FeedsModelCategory *category, categories) {
m_ui->m_cmbParentCategory->addItem(category->data(FDS_MODEL_TITLE_INDEX,
Qt::DecorationRole).value<QIcon>(),
category->title(),
QVariant::fromValue((void*) category));
}
}

View File

@ -12,6 +12,8 @@ namespace Ui {
class FeedsModel;
class FeedsModelStandardFeed;
class FeedsModelCategory;
class FeedsModelRootItem;
class FormStandardFeedDetails : public QDialog {
Q_OBJECT
@ -25,10 +27,23 @@ class FormStandardFeedDetails : public QDialog {
int exec(FeedsModelStandardFeed *input_feed);
protected:
void setEditableFeed(FeedsModelStandardFeed *editable_feed);
void initialize();
// Loads categories into the dialog from the model.
void loadCategories(const QList<FeedsModelCategory*> categories,
FeedsModelRootItem *root_item,
FeedsModelStandardFeed *input_feed);
private:
Ui::FormStandardFeedDetails *m_ui;
FeedsModelStandardFeed *m_editableFeed;
FeedsModel *m_feedsModel;
QMenu *m_iconMenu;
QAction *m_actionLoadIconFromFile;
QAction *m_actionUseDefaultIcon;
QAction *m_actionNoIcon;
};
#endif // FORMSTANDARDFEEDDETAILS_H

View File

@ -84,7 +84,7 @@
</widget>
</item>
<item row="4" column="1">
<widget class="LineEditWithStatus" name="widget" native="true"/>
<widget class="LineEditWithStatus" name="m_txtUrl" native="true"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_2">