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

PIMPrint Library

  • sources
  • kde-4.14
  • kdepim
  • pimprint
  • calendar
cellitem.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program 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
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 
18  As a special exception, permission is given to link this program
19  with any edition of Qt, and distribute the resulting executable,
20  without including the source code for Qt in the source distribution.
21 */
22 //krazy:excludeall=kdebug since the debug area used is for very verbose
23 
24 #include "cellitem.h"
25 
26 #include <KDebug>
27 #include <KLocale>
28 
29 using namespace PimPrint::Calendar;
30 
31 QString CellItem::label() const
32 {
33  return i18n("<placeholder>undefined</placeholder>");
34 }
35 
36 QList<CellItem *> CellItem::placeItem(QList<CellItem *> cells, CellItem *placeItem)
37 {
38  kDebug(5855) << "Placing" << placeItem->label();
39 
40  QList<CellItem *> conflictItems;
41  int maxSubCells = 0;
42  QMultiHash<int, CellItem *> subCellDict;
43 
44  // Find all items which are in same cell
45  QList<CellItem *>::iterator it;
46  for (it = cells.begin(); it != cells.end(); ++it) {
47  CellItem *item = *it;
48  if (item == placeItem) {
49  continue;
50  }
51 
52  if (item->overlaps(placeItem)) {
53  kDebug(5855) << " Overlaps:" << item->label();
54 
55  conflictItems.append(item);
56  if (item->subCells() > maxSubCells) {
57  maxSubCells = item->subCells();
58  }
59  subCellDict.insert(item->subCell(), item);
60  }
61  }
62 
63  if (!conflictItems.empty()) {
64  // Look for unused sub cell and insert item
65  int i;
66  for (i = 0; i < maxSubCells; ++i) {
67  kDebug(5855) << " Trying subcell" << i;
68  if (!subCellDict.contains(i)) {
69  kDebug(5855) << " Use subcell" << i;
70  placeItem->setSubCell(i);
71  break;
72  }
73  }
74  if (i == maxSubCells) {
75  kDebug(5855) << " New subcell" << i;
76  placeItem->setSubCell(maxSubCells);
77  maxSubCells++; // add new item to number of sub cells
78  }
79 
80  kDebug(5855) << " Sub cells:" << maxSubCells;
81 
82  // Write results to item to be placed
83  conflictItems.append(placeItem);
84  placeItem->setSubCells(maxSubCells);
85 
86  QList<CellItem *>::iterator it;
87  for (it = conflictItems.begin(); it != conflictItems.end(); ++it) {
88  (*it)->setSubCells(maxSubCells);
89  }
90  // Todo: Adapt subCells of items conflicting with conflicting items
91  } else {
92  kDebug(5855) << " no conflicts";
93  placeItem->setSubCell(0);
94  placeItem->setSubCells(1);
95  }
96 
97  return conflictItems;
98 }
PimPrint::Calendar::CellItem
Definition: cellitem.h:37
cellitem.h
PimPrint::Calendar::CellItem::setSubCell
void setSubCell(int v)
Definition: cellitem.h:59
PimPrint::Calendar::CellItem::overlaps
virtual bool overlaps(CellItem *other) const =0
PimPrint::Calendar::CellItem::subCells
int subCells() const
Definition: cellitem.h:54
QMultiHash::contains
bool contains(const Key &key) const
QList::append
void append(const T &value)
QList::empty
bool empty() const
PimPrint::Calendar::CellItem::setSubCells
void setSubCells(int v)
Definition: cellitem.h:49
QString
QList
QMultiHash::insert
QHash< Key, T >::iterator insert(const Key &key, const T &value)
QList::iterator
QList::end
iterator end()
PimPrint::Calendar::CellItem::subCell
int subCell() const
Definition: cellitem.h:64
PimPrint::Calendar::CellItem::label
virtual QString label() const
Definition: cellitem.cpp:31
PimPrint::Calendar::CellItem::placeItem
static QList< CellItem * > placeItem(QList< CellItem * > cells, CellItem *placeItem)
Place item placeItem into stripe containing items cells in a way that items don't overlap...
Definition: cellitem.cpp:36
QList::begin
iterator begin()
QMultiHash
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PIMPrint Library

Skip menu "PIMPrint Library"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

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
  • pimprint

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