Exemple #1
0
bool CSMFilter::TextNode::test (const CSMWorld::IdTableBase& table, int row,
    const std::map<int, int>& columns) const
{
    const std::map<int, int>::const_iterator iter = columns.find (mColumnId);

    if (iter==columns.end())
        throw std::logic_error ("invalid column in text node test");

    if (iter->second==-1)
        return true;

    QModelIndex index = table.index (row, iter->second);

    QVariant data = table.data (index);

    QString string;

    if (data.type()==QVariant::String)
    {
        string = data.toString();
    }
    else if ((data.type()==QVariant::Int || data.type()==QVariant::UInt) &&
        CSMWorld::Columns::hasEnums (static_cast<CSMWorld::Columns::ColumnId> (mColumnId)))
    {
        int value = data.toInt();

        std::vector<std::string> enums =
            CSMWorld::Columns::getEnums (static_cast<CSMWorld::Columns::ColumnId> (mColumnId));

        if (value>=0 && value<static_cast<int> (enums.size()))
            string = QString::fromUtf8 (enums[value].c_str());
    }
    else if (data.type()==QVariant::Bool)
    {
        string = data.toBool() ? "true" : "false";
    }
    else if (mText.empty() && !data.isValid())
        return true;
    else
        return false;

    /// \todo make pattern syntax configurable
    QRegExp regExp (QString::fromUtf8 (mText.c_str()), Qt::CaseInsensitive);

    return regExp.exactMatch (string);
}
Exemple #2
0
bool CSMFilter::ValueNode::test (const CSMWorld::IdTableBase& table, int row,
    const std::map<int, int>& columns) const
{
    const std::map<int, int>::const_iterator iter = columns.find (mColumnId);

    if (iter==columns.end())
        throw std::logic_error ("invalid column in value node test");

    if (iter->second==-1)
        return true;

    QModelIndex index = table.index (row, iter->second);

    QVariant data = table.data (index);

    if (data.type()!=QVariant::Double && data.type()!=QVariant::Bool && data.type()!=QVariant::Int &&
        data.type()!=QVariant::UInt && data.type()!=static_cast<QVariant::Type> (QMetaType::Float))
        return false;

    double value = data.toDouble();

    switch (mLowerType)
    {
        case Type_Closed: if (value<mLower) return false; break;
        case Type_Open: if (value<=mLower) return false; break;
        case Type_Infinite: break;
    }

    switch (mUpperType)
    {
        case Type_Closed: if (value>mUpper) return false; break;
        case Type_Open: if (value>=mUpper) return false; break;
        case Type_Infinite: break;
    }

    return true;
}