Ejemplo n.º 1
0
void FieldFilterEdit::checkFilter(const QString& filter_text)
{
    popFilterSyntaxStatus();
    checkDisplayFilter(filter_text);

    switch (syntaxState()) {
    case Deprecated:
    {
        emit pushFilterSyntaxWarning(syntaxErrorMessage());
        break;
    }
    case Invalid:
    {
        QString invalidMsg(tr("Invalid filter: "));
        invalidMsg.append(syntaxErrorMessage());
        emit pushFilterSyntaxStatus(invalidMsg);
        break;
    }
    default:
        break;
    }
}
Ejemplo n.º 2
0
void DisplayFilterEdit::checkFilter(const QString& filter_text)
{
    if (clear_button_) {
        clear_button_->setVisible(!filter_text.isEmpty());
    }

    popFilterSyntaxStatus();
    checkDisplayFilter(filter_text);

    switch (syntaxState()) {
    case Deprecated:
    {
        /*
         * We're being lazy and only printing the first "problem" token.
         * Would it be better to print all of them?
         */
        QString deprecatedMsg(tr("\"%1\" may have unexpected results (see the User's Guide)")
                .arg(deprecatedToken()));
        emit pushFilterSyntaxWarning(deprecatedMsg);
        break;
    }
    case Invalid:
    {
        QString invalidMsg(tr("Invalid filter: "));
        invalidMsg.append(syntaxErrorMessage());
        emit pushFilterSyntaxStatus(invalidMsg);
        break;
    }
    default:
        break;
    }

    if (bookmark_button_) {
        bool enable_save_action = false;
        bool match = false;
        QMenu *bb_menu = bookmark_button_->menu();

        bb_menu->clear();
        QAction *save_action = bb_menu->addAction(tr("Save this filter"));
        connect(save_action, SIGNAL(triggered(bool)), this, SLOT(saveFilter()));
        QAction *manage_action = bb_menu->addAction(tr("Manage Display Filters"));
        connect(manage_action, SIGNAL(triggered(bool)), this, SLOT(showFilters()));
        QAction *expr_action = bb_menu->addAction(tr("Manage Filter Expressions"));
        connect(expr_action, SIGNAL(triggered(bool)), this, SLOT(showExpressionPrefs()));

        QAction *first_filter = NULL;
        for (GList *df_item = get_filter_list_first(DFILTER_LIST); df_item; df_item = g_list_next(df_item)) {
            if (!df_item->data) continue;
            filter_def *df_def = (filter_def *) df_item->data;
            if (!df_def->name || !df_def->strval) continue;

            int one_em = bb_menu->fontMetrics().height();
            QString prep_text = QString("%1: %2").arg(df_def->name).arg(df_def->strval);
            prep_text = bb_menu->fontMetrics().elidedText(prep_text, Qt::ElideRight, one_em * 40);

            QAction *prep_action = bb_menu->addAction(prep_text);
            prep_action->setData(df_def->strval);
            connect(prep_action, SIGNAL(triggered(bool)), this, SLOT(prepareFilter()));
            if (!first_filter) first_filter = prep_action;

            if (filter_text.compare(df_def->strval) == 0) {
                match = true;
            }
        }
        if (first_filter) bb_menu->insertSeparator(first_filter);

        if (match) {
            bookmark_button_->setStockIcon("x-filter-matching-bookmark");
            QAction *remove_action = new QAction(tr("Remove this filter"), bb_menu);
            bb_menu->insertAction(manage_action, remove_action);
            remove_action->setData(filter_text);
            connect(remove_action, SIGNAL(triggered(bool)), this, SLOT(removeFilter()));
        } else {
            bookmark_button_->setStockIcon("x-filter-bookmark");
        }

        if (!match && (syntaxState() == Valid || syntaxState() == Deprecated) && !filter_text.isEmpty()) {
            enable_save_action = true;
        }
        save_action->setEnabled(enable_save_action);
    }