• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

calendarsupport

  • sources
  • kde-4.12
  • kdepim
  • calendarsupport
categoryhierarchyreader.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005 Rafal Rzepecki <divide@users.sourceforge.net>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "categoryhierarchyreader.h"
21 #include "categoryconfig.h"
22 #include <KComboBox>
23 #include <QTreeWidget>
24 
25 using namespace CalendarSupport;
26 
27 inline QString &quote( QString &string )
28 {
29  Q_ASSERT( CategoryConfig::categorySeparator != QLatin1String("@") );
30  return string.replace( QLatin1Char('@'), QLatin1String("@0") ).replace( QLatin1Char( '\\' ) +
31  CategoryConfig::categorySeparator,
32  QLatin1String("@1") );
33 }
34 
35 inline QStringList &unquote( QStringList &strings )
36 {
37  return
38  strings.replaceInStrings( QLatin1String("@1"), CategoryConfig::categorySeparator ).
39  replaceInStrings( QLatin1String("@0"), QLatin1String("@") );
40 }
41 
42 QStringList CategoryHierarchyReader::path( QString string )
43 {
44  QStringList _path =
45  quote( string ).split( CategoryConfig::categorySeparator, QString::SkipEmptyParts );
46  return unquote( _path );
47 }
48 
49 void CategoryHierarchyReader::read( QStringList categories )
50 {
51  clear();
52  QStringList::Iterator it;
53 
54  // case insensitive sort
55  QMap<QString, QString> map;
56  foreach ( const QString &str, categories ) {
57  map.insert( str.toLower(), str );
58  }
59 
60  categories = map.values();
61 
62  QStringList last_path;
63  for ( it = categories.begin(); it != categories.end(); ++it ) {
64  QStringList _path = path( *it );
65 
66  // we need to figure out where last item and the new one differ
67  QStringList::Iterator jt, kt;
68  int split_level = 0;
69  QStringList new_path = _path; // save it for later
70  for ( jt = _path.begin(), kt = last_path.begin();
71  jt != _path.end() && kt != last_path.end(); ++jt, ++kt ) {
72  if ( *jt == *kt ) {
73  split_level++;
74  } else {
75  break; // now we have first non_equal component in the iterators
76  }
77  }
78 
79  // make a path relative to the shared ancestor
80  if ( jt != _path.begin() ) {
81  _path.erase( _path.begin(), jt );
82  }
83  last_path = new_path;
84 
85  if ( _path.isEmpty() ) {
86  // something is wrong, we already have this node
87  continue;
88  }
89 
90  // find that ancestor
91  while ( split_level < depth() ) {
92  goUp();
93  }
94  Q_ASSERT( split_level == depth() );
95 
96  // make the node and any non-existent ancestors
97  while ( !_path.isEmpty() ) {
98  addChild( _path.first(), QVariant( *it ) );
99  _path.pop_front();
100  }
101  }
102 }
103 
104 void CategoryHierarchyReaderQComboBox::clear()
105 {
106  mBox->clear();
107 }
108 
109 void CategoryHierarchyReaderQComboBox::goUp()
110 {
111  mCurrentDepth--;
112 }
113 
114 void CategoryHierarchyReaderQComboBox::addChild( const QString &label, const QVariant &userData )
115 {
116  QString spaces;
117  spaces.fill( QLatin1Char(' '), 2 * mCurrentDepth );
118  mBox->addItem( spaces + label, userData );
119  mCurrentDepth++;
120 }
121 
122 int CategoryHierarchyReaderQComboBox::depth() const
123 {
124  return mCurrentDepth;
125 }
126 
127 #ifndef QT_NO_TREEWIDGET
128 
129 void CategoryHierarchyReaderQTreeWidget::clear()
130 {
131  mTree->clear();
132 }
133 
134 void CategoryHierarchyReaderQTreeWidget::goUp()
135 {
136  Q_ASSERT( mItem );
137  mItem = mItem->parent();
138  --mCurrentDepth;
139 }
140 
141 void CategoryHierarchyReaderQTreeWidget::addChild( const QString &label, const QVariant &userData )
142 {
143  Q_UNUSED( userData );
144 
145  if ( mItem ) {
146  mItem = new QTreeWidgetItem( mItem, QStringList() << label );
147  } else {
148  mItem = new QTreeWidgetItem( mTree, QStringList() << label );
149  }
150 
151  mItem->setExpanded( true );
152  ++mCurrentDepth;
153 }
154 
155 int CategoryHierarchyReaderQTreeWidget::depth() const
156 {
157  return mCurrentDepth;
158 }
159 #endif
CalendarSupport::CategoryHierarchyReader::read
void read(QStringList categories)
Definition: categoryhierarchyreader.cpp:49
CalendarSupport::CategoryHierarchyReader::clear
virtual void clear()=0
CalendarSupport::CategoryHierarchyReaderQComboBox::goUp
virtual void goUp()
Definition: categoryhierarchyreader.cpp:109
CalendarSupport::CategoryHierarchyReader::depth
virtual int depth() const =0
CalendarSupport::CategoryHierarchyReaderQTreeWidget::goUp
virtual void goUp()
Definition: categoryhierarchyreader.cpp:134
CalendarSupport::CategoryHierarchyReader::addChild
virtual void addChild(const QString &label, const QVariant &userData=QVariant())=0
CalendarSupport::CategoryConfig::categorySeparator
static const QString categorySeparator
Definition: categoryconfig.h:47
CalendarSupport::CategoryHierarchyReaderQComboBox::addChild
virtual void addChild(const QString &label, const QVariant &userData=QVariant())
Definition: categoryhierarchyreader.cpp:114
categoryhierarchyreader.h
CalendarSupport::CategoryHierarchyReaderQComboBox::depth
virtual int depth() const
Definition: categoryhierarchyreader.cpp:122
CalendarSupport::categories
CALENDARSUPPORT_EXPORT QStringList categories(const KCalCore::Incidence::List &incidences)
Definition: utils.cpp:746
CalendarSupport::CategoryHierarchyReader::goUp
virtual void goUp()=0
CalendarSupport::CategoryHierarchyReaderQComboBox::clear
virtual void clear()
Definition: categoryhierarchyreader.cpp:104
CalendarSupport::CategoryHierarchyReaderQTreeWidget::addChild
virtual void addChild(const QString &label, const QVariant &userData=QVariant())
Definition: categoryhierarchyreader.cpp:141
CalendarSupport::CategoryHierarchyReader::path
static QStringList path(QString string)
Definition: categoryhierarchyreader.cpp:42
CalendarSupport::CategoryHierarchyReaderQTreeWidget::depth
virtual int depth() const
Definition: categoryhierarchyreader.cpp:155
unquote
QStringList & unquote(QStringList &strings)
Definition: categoryhierarchyreader.cpp:35
quote
QString & quote(QString &string)
Definition: categoryhierarchyreader.cpp:27
categoryconfig.h
CalendarSupport::CategoryHierarchyReaderQTreeWidget::clear
virtual void clear()
Definition: categoryhierarchyreader.cpp:129
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:54:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

calendarsupport

Skip menu "calendarsupport"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal