<commit_before>/* This file is part of Mapnik (c++ mapping toolkit)
 * Copyright (C) 2007 <NAME>
 *
 * Mapnik is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

//$Id$

#include "styles_model.hpp"
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>
#include <QList>
#include <QIcon>

class node : private boost::noncopyable
{
      struct node_base
      {
            virtual QString name() const=0;
            virtual QIcon   icon() const=0;
            virtual ~node_base() {}
      };
      
      template <typename T>
      struct wrap : public node_base
      {
            wrap(T const& obj)
               : obj_(obj) {}
            
            ~wrap() {}
            
            QString name () const
            {
               return obj_.name();
            }
            
            QIcon icon() const
            {
               return obj_.icon();
            }
            
            T obj_;
      };
      
   public:
      template <typename T> 
      node ( T const& obj, node * parent=0)
         : impl_(new wrap<T>(obj)),
           parent_(parent)
      {}
      
      QString name() const
      {
         return impl_->name();
      }
      
      QIcon icon() const
      {
         return impl_->icon();
      }
      
      unsigned num_children() const
      {
         return children_.count();
      }
      
      node * child(unsigned row) const
      {
         return children_.value(row);
      }
      
      node * parent() const
      {
         return parent_;
      }
      
      node * add_child(node * child)
      {
         children_.push_back(child);
         return child;
      }
      int row () const
      {
         if (parent_)
            return parent_->children_.indexOf(const_cast<node*>(this));
         else
            return 0;
      }
      
      ~node() 
      {
         qDeleteAll(children_);
      }
      
   private:
      boost::scoped_ptr<node_base> impl_;
      QList<node*> children_;
      node * parent_;
};

class rule_node
{
   public:
      rule_node(QString name,mapnik::rule_type const & r)
         : name_(name),
           rule_(r) {}
      ~rule_node() {}
      QString name() const
      {
         mapnik::filter_ptr filter = rule_.get_filter();
         
         return QString(filter->to_string().c_str());
      } 
      
      QIcon icon() const
      {
         return QIcon(":/images/filter.png");
      }
      
   private:
      QString name_;
      mapnik::rule_type const& rule_;
};

class style_node
{
   public:
      style_node(QString name, mapnik::feature_type_style const& style)
         : name_(name),
           style_(style) {}
      
      ~style_node() {}
      
      QString name() const
      {
         return name_;
      }
      
      QIcon icon() const
      {
         return QIcon(":/images/style.png");
      }
      
   private:
      QString name_;
      mapnik::feature_type_style const& style_;
};

class map_node
{
   public:
      explicit map_node(boost::shared_ptr<mapnik::Map> map)
         : map_(map)  {}
      ~map_node() {}
      
      QString name() const
      {
         return QString("Map");
      }
      
      QIcon icon() const
      {
         return QIcon(":/images/map.png");
      }
      
   private:
      boost::shared_ptr<mapnik::Map> map_;
};

StyleModel::StyleModel(boost::shared_ptr<mapnik::Map> map, QObject * parent)
   : QAbstractItemModel(parent),
     root_(new node(map_node(map))) 
{
   typedef std::map<std::string,mapnik::feature_type_style> style_type; 
   style_type const & styles = map->styles();
   style_type::const_iterator itr = styles.begin();
   style_type::const_iterator end = styles.end();
   for (; itr != end; ++itr)
   {
      node * style = root_->add_child(new node(style_node(QString(itr->first.c_str()),itr->second),root_.get()));
      mapnik::rules const& rules = itr->second.get_rules();
      mapnik::rules::const_iterator itr2 = rules.begin();
      for ( ; itr2 != rules.end();++itr2)
      {
         style->add_child(new node(rule_node(QString("Rule"),*itr2),style));
      }
   }   
}

StyleModel::~StyleModel() {}<commit_msg>added symbilizer node to the Layer TreeView<commit_after>/* This file is part of Mapnik (c++ mapping toolkit)
 * Copyright (C) 2007 <NAME>
 *
 * Mapnik is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

//$Id$

#include "styles_model.hpp"
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>
#include <QList>
#include <QIcon>

class node : private boost::noncopyable
{
      struct node_base
      {
            virtual QString name() const=0;
            virtual QIcon   icon() const=0;
            virtual ~node_base() {}
      };
      
      template <typename T>
      struct wrap : public node_base
      {
            wrap(T const& obj)
               : obj_(obj) {}
            
            ~wrap() {}
            
            QString name () const
            {
               return obj_.name();
            }
            
            QIcon icon() const
            {
               return obj_.icon();
            }
            
            T obj_;
      };
      
   public:
      template <typename T> 
      node ( T const& obj, node * parent=0)
         : impl_(new wrap<T>(obj)),
           parent_(parent)
      {}
      
      QString name() const
      {
         return impl_->name();
      }
      
      QIcon icon() const
      {
         return impl_->icon();
      }
      
      unsigned num_children() const
      {
         return children_.count();
      }
      
      node * child(unsigned row) const
      {
         return children_.value(row);
      }
      
      node * parent() const
      {
         return parent_;
      }
      
      node * add_child(node * child)
      {
         children_.push_back(child);
         return child;
      }
      int row () const
      {
         if (parent_)
            return parent_->children_.indexOf(const_cast<node*>(this));
         else
            return 0;
      }
      
      ~node() 
      {
         qDeleteAll(children_);
      }
      
   private:
      boost::scoped_ptr<node_base> impl_;
      QList<node*> children_;
      node * parent_;
};

struct symbolizer_info : public boost::static_visitor<QString>
{
      QString operator() (mapnik::point_symbolizer const& sym) const
      {
         return QString("PointSymbolizer");
      }
      
      QString operator() (mapnik::line_symbolizer const& sym) const
      {
         return QString("LineSymbolizer");
      }

      QString operator() (mapnik::line_pattern_symbolizer const& sym) const
      {
         return QString("LinePatternSymbolizer");
      }

      QString operator() (mapnik::polygon_symbolizer const& sym) const
      {
         return QString("PolygonSymbolizer");
      }

      QString operator() (mapnik::polygon_pattern_symbolizer const& sym) const
      {
         return QString("PolygonSymbolizer");
      }
            
      QString operator() (mapnik::text_symbolizer const& sym) const
      {
         return QString("TextSymbolizer");
      }
      
      QString operator() (mapnik::shield_symbolizer const& sym) const
      {
         return QString("ShieldSymbolizer");
      }
      
      template <typename T>
      QString operator() (T const& ) const
      {
         return QString ("FIXME");
      }
};

class symbolizer_node
{
   public:
      symbolizer_node(mapnik::symbolizer const & sym)
         : sym_(sym) {}
      ~symbolizer_node(){}
      
      QString name() const 
      {
         //return QString("Symbolizer:fixme");
         return boost::apply_visitor(symbolizer_info(),sym_);
      }
      
      QIcon icon() const
      {
         return QIcon(":/images/filter.png");
      }
      mapnik::symbolizer const& sym_;
};

class rule_node
{
   public:
      rule_node(QString name,mapnik::rule_type const & r)
         : name_(name),
           rule_(r) {}
      ~rule_node() {}
      QString name() const
      {
         mapnik::filter_ptr filter = rule_.get_filter();
         
         return QString(filter->to_string().c_str());
      } 
      
      QIcon icon() const
      {
         return QIcon(":/images/filter.png");
      }
      
   private:
      QString name_;
      mapnik::rule_type const& rule_;
};

class style_node
{
   public:
      style_node(QString name, mapnik::feature_type_style const& style)
         : name_(name),
           style_(style) {}
      
      ~style_node() {}
      
      QString name() const
      {
         return name_;
      }
      
      QIcon icon() const
      {
         return QIcon(":/images/style.png");
      }
      
   private:
      QString name_;
      mapnik::feature_type_style const& style_;
};

class map_node
{
   public:
      explicit map_node(boost::shared_ptr<mapnik::Map> map)
         : map_(map)  {}
      ~map_node() {}
      
      QString name() const
      {
         return QString("Map");
      }
      
      QIcon icon() const
      {
         return QIcon(":/images/map.png");
      }
      
   private:
      boost::shared_ptr<mapnik::Map> map_;
};

StyleModel::StyleModel(boost::shared_ptr<mapnik::Map> map, QObject * parent)
   : QAbstractItemModel(parent),
     root_(new node(map_node(map))) 
{
   typedef std::map<std::string,mapnik::feature_type_style> style_type; 
   style_type const & styles = map->styles();
   style_type::const_iterator itr = styles.begin();
   style_type::const_iterator end = styles.end();
   for (; itr != end; ++itr)
   {
      node * style_n = root_->add_child(new node(style_node(QString(itr->first.c_str()),itr->second),root_.get()));
      mapnik::rules const& rules = itr->second.get_rules();
      mapnik::rules::const_iterator itr2 = rules.begin();
      for ( ; itr2 != rules.end();++itr2)
      {
         node* rule_n = style_n->add_child(new node(rule_node(QString("Rule"),*itr2),style_n));
         mapnik::symbolizers::const_iterator itr3 = (*itr2).begin();
         for ( ; itr3 !=itr2->end();++itr3)
         {
            rule_n->add_child(new node(symbolizer_node(*itr3),rule_n));
         }
      }
   }   
}

StyleModel::~StyleModel() {}
{'fraction_non_alphanumeric': 0.11535087719298245, 'fraction_numerical': 0.005263157894736842, 'mean_word_length': 1.9032340208810796, 'pattern_counts': {'":': 7, '<': 35, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2461043', 'n_tokens_mistral': 3353, 'n_tokens_neox': 3345, 'n_words': 822}