QVariant CheckableTagModel::data(const QModelIndex &proxyIndex, int role) const
{
    if (!sourceModel() || !proxyIndex.isValid())
        return QVariant();

    QModelIndex sourceIndex = sourceModel()->index(proxyIndex.row(), 0);
    if (!sourceIndex.isValid())
        return QVariant();

    if (role == Qt::CheckStateRole) {
        Tag::Ptr tag = sourceIndex.data(Storage::TagPtrRole).value<Tag::Ptr>();
        if (!tag) {
            qWarning() << Q_FUNC_INFO <<"Unexpected null tag";
            return false;
        }

        return m_parentTask->containsTag(tag->name());
    } else if (role == CheckableRole) {
        return true;
    } else if (role == ItemTextRole)  {
        Tag::Ptr tag = sourceIndex.data(Storage::TagPtrRole).value<Tag::Ptr>();
        if (!tag) {
            qWarning() << Q_FUNC_INFO <<"Unexpected null tag";
            return QString();
        }

        return tag->name();
    }

    return sourceIndex.data(role);
}
示例#2
0
SAWYER_EXPORT void
PodFormatter::endTag(std::ostream &out, const Tag::Ptr &tag, const TagArgs &args) {
    ASSERT_forbid(tagStack_.empty());
    ASSERT_require(tagStack_.back()==tag);
    tagStack_.pop_back();
    if (tag->type() == DIVIDING)
        out <<(atBeginningOfLine_?"":"\n") <<"\n";

    if (tag->name() == "list") {
        out <<"=back\n\n";
    } else if (tag->name() == "prose" || tag->name() == "nonprose") {
        out <<"=back\n\n";
        textModePop();
    }
}
示例#3
0
 /// <summary>
 /// Evaluates the specified tag and returns <value>true</value>
 /// if it's a tag which represents a notebook.
 /// </summary>
 /// <param name="tag">
 /// A <see cref="Tag"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 bool NotebookManager::is_notebook_tag(const Tag::Ptr & tag)
 {
   std::string fullTagName = tag->name();
   return Glib::str_has_prefix(fullTagName,
                               std::string(Tag::SYSTEM_TAG_PREFIX)
                               + Notebook::NOTEBOOK_TAG_PREFIX);
 }
示例#4
0
// Check that the expected number of arguments are present.
SAWYER_EXPORT void
PodFormatter::checkArgs(const Tag::Ptr &tag, size_t nArgs, const TagArgs &args) const {
    if (args.size()!=nArgs) {
        std::ostringstream ss;
        ss <<"expected " <<nArgs <<" argument" <<(1==nArgs?"":"s") <<" for @" <<tag->name() <<" but got " <<args.size();
        throw std::runtime_error(ss.str());
    }
}
示例#5
0
void NotebookApplicationAddin::on_tag_added(const Note & note, const Tag::Ptr& tag)
{
    if (NotebookManager::instance().is_adding_notebook()) {
        return;
    }

    std::string megaPrefix(Tag::SYSTEM_TAG_PREFIX);
    megaPrefix += Notebook::NOTEBOOK_TAG_PREFIX;
    if (!tag->is_system() || !Glib::str_has_prefix(tag->name(), megaPrefix)) {
        return;
    }

    std::string notebookName =
        sharp::string_substring(tag->name(), megaPrefix.size());

    Notebook::Ptr notebook =
        NotebookManager::instance().get_or_create_notebook (notebookName);

    NotebookManager::instance().signal_note_added_to_notebook() (note, notebook);
}
示例#6
0
 /// <summary>
 /// Construct a new Notebook with the specified notebook system tag.
 /// </summary>
 /// <param name="notebookTag">
 /// A <see cref="Tag"/>.  This must be a system notebook tag.
 /// </param>
 Notebook::Notebook(const Tag::Ptr & notebookTag)
 {
 std::cout << __PRETTY_FUNCTION__ << std::endl;
 // Parse the notebook name from the tag name
   std::string systemNotebookPrefix = std::string(Tag::SYSTEM_TAG_PREFIX)
     + NOTEBOOK_TAG_PREFIX;
   std::string notebookName = sharp::string_substring(notebookTag->name(), 
                                                      systemNotebookPrefix.length());
   set_name(notebookName);
   m_tag = notebookTag;
 }
示例#7
0
     /// <summary>
 /// Returns the Notebook associated with the specified tag
 /// or null if the Tag does not represent a notebook.
 /// </summary>
 /// <param name="tag">
 /// A <see cref="Tag"/>
 /// </param>
 /// <returns>
 /// A <see cref="Notebook"/>
 /// </returns>
 Notebook::Ptr NotebookManager::get_notebook_from_tag(const Tag::Ptr &tag)
 {
   if (!is_notebook_tag (tag)) {
     return Notebook::Ptr();
   }
   
   // Parse off the system and notebook prefix to get
   // the name of the notebook and then look it up.
   std::string systemNotebookPrefix = std::string(Tag::SYSTEM_TAG_PREFIX)
     + Notebook::NOTEBOOK_TAG_PREFIX;
   std::string notebookName = sharp::string_substring(tag->name(), 
                                                      systemNotebookPrefix.size());
   
   return get_notebook (notebookName);
 }
示例#8
0
SAWYER_EXPORT bool
PodFormatter::beginTag(std::ostream &out, const Tag::Ptr &tag, const TagArgs &args) {
    tagStack_.push_back(tag);
    if (tag->type() == DIVIDING) {
        out <<(atBeginningOfLine_?"":"\n") <<"\n";
        atBeginningOfLine_ = true;
    }

    if (tag->name() == "prose") {
        checkArgs(tag, 1, args);
        out <<"=over\n\n";
        textModePush(PROSE);

    } else if (tag->name() == "nonprose") {
        checkArgs(tag, 1, args);
        out <<"=over\n\n";
        textModePush(NONPROSE);

    } else if (tag->name() == "section") {
        // Nested sections, but only if the body is not empty.
        checkArgs(tag, 2, args);
        size_t level = nested() + 1;
        if (level > 4)
            throw std::runtime_error("POD formatter can handle at most four levels of section nesting");
        std::ostringstream arg0, arg1;
        arg0 <<"=head" <<level <<" ";
        atBeginningOfLine_ = false;
        args[0]->emit(arg0, self());
        arg0 <<"\n\n";
        atBeginningOfLine_ = true;
        args[1]->emit(arg1, self());
        if (hasNonSpace(arg1.str()))
            out <<arg0.str() <<arg1.str();
        return false;                                   // no recursion

    } else if (tag->name() == "list") {
        out <<"=over\n\n";
        atBeginningOfLine_ = true;

    } else if (tag->name() == "bullet") {
        checkArgs(tag, 1, args);
        out <<"=item * ";
        atBeginningOfLine_ = false;

    } else if (tag->name() == "numbered") {
        checkArgs(tag, 1, args);
        out <<"=item 1 ";
        atBeginningOfLine_ = false;

    } else if (tag->name() == "named") {
        checkArgs(tag, 2, args);
        out <<"=item ";
        args[0]->emit(out, self());
        out <<"\n\n";
        atBeginningOfLine_ = true;
        args[1]->emit(out, self());
        return false;

    } else if (tag->name() == "comment") {
        return false;

    } else if (tag->name() == "emphasis") {
        checkArgs(tag, 1, args);
        out <<(nested() % 2 ? 'B' : 'I') <<'<';
        atBeginningOfLine_ = false;
        args[0]->emit(out, self());
        out <<">";
        atBeginningOfLine_ = false;
        return false;
            
    } else if (tag->name() == "variable") {
        checkArgs(tag, 1, args);
        out <<"I<";
        atBeginningOfLine_ = false;
        args[0]->emit(out, self());
        out <<">";
        atBeginningOfLine_ = false;
        return false;

    } else if (tag->name() == "link") {                 // second arg (text) is ignored; only link is shown
        checkArgs(tag, 2, args);
        out <<"L<";
        atBeginningOfLine_ = false;
        args[0]->emit(out, self());
        out <<">";
        atBeginningOfLine_ = false;
        return false;

    } else if (tag->name() == "verbatim") {

    } else {
        throw std::runtime_error("unrecognized markup tag \"" + tag->name() + "\" for Perl POD formatter");
    }
    return true;
}