void Settings::BirthdayPage::changeCategory(int index)
{
    m_lastItem = nullptr;
    m_dataView->clear();
    m_dataView->setSortingEnabled(false);
    m_dataView->setHorizontalHeaderLabels(QStringList() << i18n("Name") << i18n("Birthday"));

    const QString categoryName = m_categoryBox->itemText(index);
    const DB::CategoryPtr category = DB::ImageDB::instance()->categoryCollection()->categoryForName(categoryName);
    QStringList items = category->items();

    m_dataView->setRowCount(items.count());
    int row = 0;

    for (const QString& text : items) {
        if (! m_filter->text().isEmpty()
            && text.indexOf(m_filter->text(), 0, Qt::CaseInsensitive) == -1) {
            m_dataView->setRowCount(m_dataView->rowCount() - 1);
            continue;
        }

        QTableWidgetItem* nameItem = new QTableWidgetItem(text);
        nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
        m_dataView->setItem(row, 0, nameItem);

        QDate dateForItem;
        if (m_changedData.contains(categoryName)) {
            if (m_changedData[categoryName].contains(text)) {
                dateForItem = m_changedData[categoryName][text];
            } else {
                dateForItem = category->birthDate(text);
            }
        } else {
            dateForItem = category->birthDate(text);
        }

        DateTableWidgetItem* dateItem = new DateTableWidgetItem(textForDate(dateForItem));
        dateItem->setData(Qt::UserRole, dateForItem);
        dateItem->setFlags(dateItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
        m_dataView->setItem(row, 1, dateItem);

        row++;
    }

    m_dataView->setSortingEnabled(true);
    m_dataView->sortItems(0);

    disableCalendar();
}
Пример #2
0
void XMLDB::FileWriter::saveCategories( QXmlStreamWriter& writer )
{
    QStringList categories = DB::ImageDB::instance()->categoryCollection()->categoryNames();
    ElementWriter dummy(writer, QString::fromLatin1("Categories") );

    DB::CategoryPtr tokensCategory = DB::ImageDB::instance()->categoryCollection()->categoryForSpecial( DB::Category::TokensCategory );
    for (QString name : categories) {
        DB::CategoryPtr category = DB::ImageDB::instance()->categoryCollection()->categoryForName(name);

        if (! shouldSaveCategory(name)) {
            continue;
        }

        ElementWriter dummy(writer, QString::fromUtf8("Category"));
        writer.writeAttribute(QString::fromUtf8("name"),  name);
        writer.writeAttribute(QString::fromUtf8("icon"), category->iconName());
        writer.writeAttribute(QString::fromUtf8("show"), QString::number(category->doShow()));
        writer.writeAttribute(QString::fromUtf8("viewtype"), QString::number(category->viewType()));
        writer.writeAttribute(QString::fromUtf8("thumbnailsize"), QString::number(category->thumbnailSize()));
        writer.writeAttribute(QString::fromUtf8("positionable"), QString::number(category->positionable()));
        if (category == tokensCategory) {
            writer.writeAttribute(QString::fromUtf8("meta"),QString::fromUtf8("tokens"));
        }

        // FIXME (l3u):
        // Correct me if I'm wrong, but we don't need this, as the tags used as groups are
        // added to the respective category anyway when they're created, so there's no need to
        // re-add them here. Apart from this, adding an empty group (one without members) does
        // add an empty tag ("") doing so.
        /*
        QStringList list =
                Utilities::mergeListsUniqly(category->items(),
                                            m_db->_members.groups(name));
        */

        Q_FOREACH(const QString &tagName, category->items()) {
            ElementWriter dummy( writer, QString::fromLatin1("value") );
            writer.writeAttribute( QString::fromLatin1("value"), tagName );
            writer.writeAttribute( QString::fromLatin1( "id" ),
                                    QString::number(static_cast<XMLCategory*>( category.data() )->idForName( tagName ) ));
            QDate birthDate = category->birthDate(tagName);
            if (!birthDate.isNull())
                writer.writeAttribute( QString::fromUtf8("birthDate"), birthDate.toString(Qt::ISODate) );
        }
    }
}