bool NonEmptyTagFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
    if (!sourceModel())
        return false;

    if (source_parent.isValid() || source_row < 0 || source_row >= sourceModel()->rowCount()) {
        qWarning() << source_parent.isValid() << source_row << sourceModel()->rowCount();
        Q_ASSERT(false);
        return false;
    }

    QModelIndex index = sourceModel()->index(source_row, 0);
    if (!index.isValid())
        return false;

    Tag::Ptr tag = index.data(Storage::TagPtrRole).value<Tag::Ptr>();
    if (!tag) {
        Q_ASSERT(false);
        return false;
    }

    if (tag->isFake()) // All and Untagged don't depend on rowCount
        return true;

    connect(static_cast<TaskFilterProxyModel*>(tag.data()->taskModel()), &TaskFilterProxyModel::countChanged,
            this, &NonEmptyTagFilterProxy::onSourceCountChanged, Qt::UniqueConnection);

    return tag->taskModel()->rowCount() > 0;
}
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);
}
示例#3
0
  std::vector<Glib::ustring> RemoteControl::GetAllNotesWithTag(const Glib::ustring& tag_name)
  {
    Tag::Ptr tag = ITagManager::obj().get_tag(tag_name);
    if (!tag)
      return std::vector<Glib::ustring>();

    std::vector<Glib::ustring> tagged_note_uris;
    std::list<NoteBase*> notes;
    tag->get_notes(notes);
    FOREACH(NoteBase *iter, notes) {
      tagged_note_uris.push_back(iter->uri());
    }
示例#4
0
  std::vector< std::string > RemoteControl::GetAllNotesWithTag(const std::string& tag_name)
  {
    Tag::Ptr tag = TagManager::obj().get_tag (tag_name);
    if (!tag)
      return std::vector< std::string >();

    std::vector< std::string > tagged_note_uris;
    std::list<Note *> notes;
    tag->get_notes(notes);
    for (std::list<Note *>::const_iterator iter = notes.begin();
         iter != notes.end(); ++iter) {
      tagged_note_uris.push_back((*iter)->uri());
    }
    return tagged_note_uris;
  }
示例#5
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();
    }
}
示例#6
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);
 }
示例#7
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());
    }
}
示例#8
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);
}
示例#9
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;
 }
示例#10
0
// BEGIN TagManager::remove_tag ()
// <summary>
// This will remove the tag from every note that is currently tagged
// and from the main list of tags.
// </summary>
void TagManager::remove_tag (const Tag::Ptr & tag) {
    if (!tag){
      std::cout << "TagManager.RemoveTag () called with a null tag";
      return;
    }

    if(tag->is_property() || tag->is_system()){
      m_internal_tags.erase(tag->normalized_name());
    }

    // typedef std::map<std::string, Tag::Ptr> TagMap;

    bool tag_removed = false;
    TagMap::iterator map_iter;
    map_iter = m_tag_map.find(tag->normalized_name());
    if (map_iter != m_tag_map.end()) {
      map_iter = m_tag_map.find(tag->normalized_name());
      if (map_iter != m_tag_map.end()) {
        Tag::Ptr iter = map_iter->second;
        if (!m_tags->erase(iter)) {
          std::cout << "TagManager: Removed tag: %s", tag->normalized_name().c_str();
        } 
        else { 
          // FIXME: For some really weird reason, this block actually gets called sometimes!
          std::cout << "TagManager: Call to remove tag from ListStore failed: %s", tag->normalized_name().c_str();
        }

        m_tag_map.erase(map_iter);
        std::cout << "Removed TreeIter from tag_map: %s", tag->normalized_name().c_str();
        tag_removed = true;

        std::list<Note*> notes;
        tag->get_notes(notes);
        for(std::list<Note*>::const_iterator note_iter = notes.begin();
            note_iter != notes.end(); ++note_iter) {
          (*note_iter)->remove_tag(tag);
        }
      }
    }

    return;
} // END TagManager::remove_tag ()
示例#11
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);
 }
void NodeFactoryImplementation::rebuildMap()
{
    Tag::createIfNotExists("General");
    Tag::Ptr general = Tag::get("General");

    tag_map_.clear();

    for (std::vector<NodeConstructor::Ptr>::iterator it = constructors_.begin(); it != constructors_.end();) {
        const NodeConstructor::Ptr& p = *it;

        try {
            bool has_tag = false;
            for (const Tag::Ptr& tag : p->getTags()) {
                tag_map_[tag->getName()].push_back(p);
                has_tag = true;
            }

            if (!has_tag) {
                tag_map_[general->getName()].push_back(p);
            }

            ++it;

        } catch (const NodeConstructor::NodeConstructionException& e) {
            NOTIFICATION("cannot load node: " << e.what());
            it = constructors_.erase(it);
        }
    }

    typedef std::map<std::string, std::vector<NodeConstructor::Ptr>> map;
    for (map::iterator it = tag_map_.begin(); it != tag_map_.end(); ++it) {
        std::sort(it->second.begin(), it->second.end(), compare);
    }

    tag_map_has_to_be_rebuilt_ = false;
}
示例#13
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;
}