KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

957 lines
21KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2005-2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  14. */
  15. #include <tqregexp.h>
  16. #include <tqstringlist.h>
  17. #include <kdebug.h>
  18. #include "kspread_cell.h"
  19. #include "kspread_doc.h"
  20. #include "kspread_global.h"
  21. #include "kspread_map.h"
  22. #include "kspread_sheet.h"
  23. #include "kspread_util.h"
  24. #include "kspread_view.h"
  25. #include "region.h"
  26. namespace KSpread
  27. {
  28. class Region::Private
  29. {
  30. public:
  31. Private()
  32. {
  33. view = 0;
  34. }
  35. View* view;
  36. TQValueList<Element*> cells;
  37. };
  38. /***************************************************************************
  39. class Region
  40. ****************************************************************************/
  41. Region::Region()
  42. {
  43. d = new Private();
  44. }
  45. Region::Region(View* view, const TQString& string, Sheet* sheet)
  46. {
  47. d = new Private();
  48. d->view = view;
  49. if (string.isEmpty())
  50. {
  51. return;
  52. }
  53. TQStringList substrings = TQStringList::split(';', string);
  54. TQStringList::ConstIterator end = substrings.constEnd();
  55. for (TQStringList::ConstIterator it = substrings.constBegin(); it != end; ++it)
  56. {
  57. TQString sRegion = *it;
  58. if (!sheet)
  59. {
  60. sheet = filterSheetName(sRegion);
  61. }
  62. int delimiterPos = sRegion.find(':');
  63. if (delimiterPos > -1)
  64. {
  65. // range
  66. Point ul(sRegion.left(delimiterPos));
  67. Point lr(sRegion.mid(delimiterPos + 1));
  68. if (ul.isValid() && lr.isValid())
  69. {
  70. Range* range = createRange(sRegion);
  71. range->setSheet(sheet);
  72. d->cells.append(range);
  73. }
  74. else if (ul.isValid())
  75. {
  76. Point* point = createPoint(sRegion.left(delimiterPos));
  77. point->setSheet(sheet);
  78. d->cells.append(point);
  79. }
  80. else // lr.isValid()
  81. {
  82. Point* point = createPoint(sRegion.right(delimiterPos + 1));
  83. point->setSheet(sheet);
  84. d->cells.append(point);
  85. }
  86. }
  87. else
  88. {
  89. // single cell
  90. Point* point = createPoint(sRegion);
  91. point->setSheet(sheet);
  92. d->cells.append(point);
  93. }
  94. }
  95. }
  96. Region::Region(const TQRect& rect, Sheet* sheet)
  97. {
  98. d = new Private();
  99. if (rect.isNull())
  100. {
  101. kdError(36001) << "Region::Region(const TQRect&): TQRect is empty!" << endl;
  102. return;
  103. }
  104. add(rect, sheet);
  105. }
  106. Region::Region(const TQPoint& point, Sheet* sheet)
  107. {
  108. d = new Private();
  109. if (point.isNull())
  110. {
  111. kdError(36001) << "Region::Region(const TQPoint&): TQPoint is empty!" << endl;
  112. return;
  113. }
  114. add(point, sheet);
  115. }
  116. Region::Region(const Region& list)
  117. {
  118. d = new Private();
  119. d->view = list.d->view;
  120. ConstIterator end(list.d->cells.constEnd());
  121. for (ConstIterator it = list.d->cells.constBegin(); it != end; ++it)
  122. {
  123. Element *element = *it;
  124. if (element->type() == Element::Point)
  125. {
  126. Point* point = static_cast<Point*>(element);
  127. d->cells.append(createPoint(*point));
  128. }
  129. else
  130. {
  131. Range* range = static_cast<Range*>(element);
  132. d->cells.append(createRange(*range));
  133. }
  134. }
  135. }
  136. Region::Region(int x, int y, Sheet* sheet)
  137. {
  138. d = new Private();
  139. if (x<1 || y<1)
  140. {
  141. kdError(36001) << "Region::Region(int x, int y): Coordinates are invalid!" << endl;
  142. return;
  143. }
  144. add(TQPoint(x,y), sheet);
  145. }
  146. Region::Region(int x, int y, int width, int height, Sheet* sheet)
  147. {
  148. d = new Private();
  149. if (x<1 || y<1 || width<1 || height<1)
  150. {
  151. kdError(36001) << "Region::Region(int x, int y, int width, int height): Dimensions are invalid!" << endl;
  152. return;
  153. }
  154. add(TQRect(x,y,width,height), sheet);
  155. }
  156. Region::~Region()
  157. {
  158. d->cells.clear();
  159. delete d;
  160. }
  161. View* Region::view() const
  162. {
  163. Q_ASSERT(d->view);
  164. return d->view;
  165. }
  166. void Region::setView(View* view)
  167. {
  168. d->view = view;
  169. }
  170. bool Region::isValid() const
  171. {
  172. ConstIterator end = d->cells.constEnd();
  173. for (ConstIterator it = d->cells.constBegin(); it != end; ++it)
  174. {
  175. if (!(*it)->isValid())
  176. {
  177. return false;
  178. }
  179. }
  180. return true;
  181. }
  182. bool Region::isSingular() const
  183. {
  184. if (d->cells.isEmpty() || d->cells.count() > 1 || (*d->cells.constBegin())->type() != Element::Point)
  185. {
  186. return false;
  187. }
  188. return true;
  189. }
  190. bool Region::isContiguous() const
  191. {
  192. if (d->cells.count() != 1 || !isValid())
  193. {
  194. return false;
  195. }
  196. return true;
  197. }
  198. TQString Region::name(Sheet* originSheet) const
  199. {
  200. TQStringList names;
  201. ConstIterator endOfList(d->cells.constEnd());
  202. for (ConstIterator it = d->cells.constBegin(); it != endOfList; ++it)
  203. {
  204. Element *element = *it;
  205. names += element->name(originSheet);
  206. }
  207. return names.isEmpty() ? "" : names.join(";");
  208. }
  209. Region::Element* Region::add(const TQPoint& point, Sheet* sheet)
  210. {
  211. // kdDebug() << k_funcinfo << endl;
  212. if (point.x() < 1 || point.y() < 1)
  213. {
  214. return 0;
  215. }
  216. Iterator it = insert(d->cells.end(), point, sheet, false);
  217. return (it == d->cells.end()) ? 0 : *it;
  218. }
  219. Region::Element* Region::add(const TQRect& range, Sheet* sheet)
  220. {
  221. if (range.normalize().width() == 0 || range.normalize().height() == 0)
  222. {
  223. return 0;
  224. }
  225. if (range.size() == TQSize(1,1))
  226. {
  227. return add(range.topLeft(), sheet);
  228. }
  229. Iterator it = insert(d->cells.end(), range, sheet, false);
  230. return (it == d->cells.end()) ? 0 : *it;
  231. }
  232. Region::Element* Region::add(const Region& region)
  233. {
  234. ConstIterator endOfList(region.d->cells.constEnd());
  235. for (ConstIterator it = region.d->cells.constBegin(); it != endOfList; ++it)
  236. {
  237. add((*it)->rect(), (*it)->sheet());
  238. }
  239. return d->cells.isEmpty() ? 0 : d->cells.last();
  240. }
  241. void Region::sub(const TQPoint& point)
  242. {
  243. // TODO Stefan: Improve!
  244. Iterator endOfList(d->cells.end());
  245. for (Iterator it = d->cells.begin(); it != endOfList; ++it)
  246. {
  247. Element *element = *it;
  248. if (element->rect() == TQRect(point,point))
  249. {
  250. delete element;
  251. d->cells.remove(element);
  252. break;
  253. }
  254. }
  255. }
  256. void Region::sub(const TQRect& range)
  257. {
  258. // TODO Stefan: Improve!
  259. Iterator endOfList(d->cells.end());
  260. for (Iterator it = d->cells.begin(); it != endOfList; ++it)
  261. {
  262. Element *element = *it;
  263. if (element->rect().normalize() == range.normalize())
  264. {
  265. delete element;
  266. d->cells.remove(element);
  267. break;
  268. }
  269. }
  270. }
  271. void Region::sub(const Region& region)
  272. {
  273. ConstIterator endOfList(region.constEnd());
  274. for (ConstIterator it = region.constBegin(); it != endOfList; ++it)
  275. {
  276. Element *element = *it;
  277. if (element->type() == Element::Point)
  278. {
  279. Point* point = static_cast<Point*>(element);
  280. sub(point->pos());
  281. }
  282. else
  283. {
  284. sub(element->rect());
  285. }
  286. }
  287. }
  288. Region::Element* Region::eor(const TQPoint& point, Sheet* sheet)
  289. {
  290. bool containsPoint = false;
  291. Iterator it = cells().begin();
  292. Iterator endOfList = cells().end();
  293. while (it != endOfList)
  294. {
  295. if (!(*it)->contains(point))
  296. {
  297. ++it;
  298. continue;
  299. }
  300. containsPoint = true;
  301. int x = point.x();
  302. int y = point.y();
  303. TQRect fullRange = (*it)->rect().normalize();
  304. delete *it;
  305. it = cells().remove(it);
  306. // top range
  307. int left = fullRange.left();
  308. int top = fullRange.top();
  309. int width = fullRange.width();
  310. int height = y - top;
  311. if (height > 0)
  312. {
  313. insert(it, TQRect(left, top, width, height), sheet);
  314. }
  315. // left range
  316. left = fullRange.left();
  317. top = y;
  318. width = TQMAX(0, x - left);
  319. height = 1;
  320. if (width > 0)
  321. {
  322. insert(it, TQRect(left, top, width, height), sheet);
  323. }
  324. // right range
  325. left = TQMIN(x+1, fullRange.right());
  326. top = y;
  327. width = TQMAX(0, fullRange.right() - x);
  328. height = 1;
  329. if (width > 0)
  330. {
  331. insert(it, TQRect(left, top, width, height), sheet);
  332. }
  333. // bottom range
  334. left = fullRange.left();
  335. top = y+1;
  336. width = fullRange.width();
  337. height = TQMAX(0, fullRange.bottom() - y);
  338. if (height > 0)
  339. {
  340. insert(it, TQRect(left, top, width, height), sheet);
  341. }
  342. return *it;
  343. }
  344. if (!containsPoint)
  345. {
  346. return add(point, sheet);
  347. }
  348. return 0;
  349. }
  350. Region::Iterator Region::insert(Region::Iterator pos, const TQPoint& point, Sheet* sheet, bool multi)
  351. {
  352. if (point.x() < 1 || point.y() < 1)
  353. {
  354. return pos;
  355. }
  356. bool containsPoint = false;
  357. // bool adjacentPoint = false;
  358. // TQRect neighbour;
  359. // we don't have to check for occurences?
  360. if (multi)
  361. {
  362. Point* rpoint = createPoint(point);
  363. rpoint->setSheet(sheet);
  364. return d->cells.insert(pos, rpoint);
  365. }
  366. ConstIterator endOfList(d->cells.constEnd());
  367. for (ConstIterator it = d->cells.constBegin(); it != endOfList; ++it)
  368. {
  369. Element *element = *it;
  370. if (sheet && sheet != element->sheet())
  371. {
  372. continue;
  373. }
  374. if (element->contains(point))
  375. {
  376. containsPoint = true;
  377. break;
  378. }
  379. /* else
  380. {
  381. neighbour = element->rect().normalize();
  382. neighbour.setTopLeft(neighbour.topLeft() - TQPoint(1,1));
  383. neighbour.setBottomRight(neighbour.bottomRight() + TQPoint(1,1));
  384. if (neighbour.contains(point))
  385. {
  386. adjacentPoint = true; // TODO Stefan: Implement!
  387. break;
  388. }
  389. }*/
  390. }
  391. if ( !containsPoint )
  392. {
  393. Point* rpoint = createPoint(point);
  394. rpoint->setSheet(sheet);
  395. return d->cells.insert(pos, rpoint);
  396. }
  397. return pos;
  398. }
  399. Region::Iterator Region::insert(Region::Iterator pos, const TQRect& range, Sheet* sheet, bool multi)
  400. {
  401. if (range.size() == TQSize(1,1))
  402. {
  403. return insert(pos, range.topLeft(), sheet);
  404. }
  405. if (multi)
  406. {
  407. Range* rrange = createRange(range);
  408. rrange->setSheet(sheet);
  409. return d->cells.insert(pos, rrange);
  410. }
  411. bool containsRange = false;
  412. Iterator it( d->cells.begin() );
  413. Iterator endOfList( d->cells.end() );
  414. while ( it != endOfList )
  415. {
  416. if (sheet && sheet != (*it)->sheet())
  417. {
  418. ++it;
  419. continue;
  420. }
  421. if ((*it)->contains(range))
  422. {
  423. containsRange = true;
  424. }
  425. else if (range.contains((*it)->rect()))
  426. {
  427. delete *it;
  428. it = d->cells.remove(it);
  429. continue;
  430. }
  431. ++it;
  432. }
  433. if ( !containsRange )
  434. {
  435. Range* rrange = createRange(range);
  436. rrange->setSheet(sheet);
  437. return d->cells.insert(pos, rrange);
  438. }
  439. return pos;
  440. }
  441. bool Region::isColumnAffected(uint col) const
  442. {
  443. ConstIterator endOfList(d->cells.constEnd());
  444. for (ConstIterator it = d->cells.constBegin(); it != endOfList; ++it)
  445. {
  446. Element *element = *it;
  447. TQRect normalizedRegion = element->rect().normalize();
  448. if ((int)col >= normalizedRegion.left() && (int)col <= normalizedRegion.right())
  449. {
  450. return true;
  451. }
  452. }
  453. return false;
  454. }
  455. bool Region::isRowAffected(uint row) const
  456. {
  457. ConstIterator endOfList(d->cells.constEnd());
  458. for (ConstIterator it = d->cells.constBegin(); it != endOfList; ++it)
  459. {
  460. Element *element = *it;
  461. TQRect normalizedRegion = element->rect().normalize();
  462. if ((int)row >= normalizedRegion.top() && (int)row <= normalizedRegion.bottom())
  463. {
  464. return true;
  465. }
  466. }
  467. return false;
  468. }
  469. bool Region::isColumnSelected(uint col) const
  470. {
  471. ConstIterator endOfList(d->cells.constEnd());
  472. for (ConstIterator it = d->cells.constBegin(); it != endOfList; ++it)
  473. {
  474. Element *element = *it;
  475. TQRect region = element->rect().normalize();
  476. if ((col == 0 || ((int)col >= region.left() && (int)col <= region.right())) &&
  477. region.top() == 1 && region.bottom() == KS_rowMax)
  478. {
  479. return true;
  480. }
  481. }
  482. return false;
  483. }
  484. bool Region::isRowSelected(uint row) const
  485. {
  486. ConstIterator endOfList(d->cells.constEnd());
  487. for (ConstIterator it = d->cells.constBegin(); it != endOfList; ++it)
  488. {
  489. Element *element = *it;
  490. TQRect region = element->rect().normalize();
  491. if ((row == 0 || ((int)row >= region.top() && (int)row <= region.bottom())) &&
  492. region.left() == 1 && region.right() == KS_colMax)
  493. {
  494. return true;
  495. }
  496. }
  497. return false;
  498. }
  499. bool Region::isColumnOrRowSelected() const
  500. {
  501. ConstIterator endOfList(d->cells.constEnd());
  502. for (ConstIterator it = d->cells.constBegin(); it != endOfList; ++it)
  503. {
  504. Element *element = *it;
  505. TQRect region = element->rect().normalize();
  506. if ((region.top() == 1 && region.bottom() == KS_rowMax) ||
  507. (region.left() == 1 && region.right() == KS_colMax))
  508. {
  509. return true;
  510. }
  511. }
  512. return false;
  513. }
  514. bool Region::contains(const TQPoint& point, Sheet* sheet) const
  515. {
  516. if (d->cells.isEmpty())
  517. {
  518. return false;
  519. }
  520. ConstIterator endOfList(d->cells.constEnd());
  521. for (ConstIterator it = d->cells.constBegin(); it != endOfList; ++it)
  522. {
  523. Element *element = *it;
  524. if (element->contains(point))
  525. {
  526. if (sheet && element->sheet() != sheet)
  527. {
  528. return false;
  529. }
  530. return true;
  531. }
  532. }
  533. return false;
  534. }
  535. bool Region::isEmpty() const
  536. {
  537. return d->cells.isEmpty();
  538. }
  539. void Region::clear()
  540. {
  541. Iterator end(d->cells.end());
  542. for (Iterator it = d->cells.begin(); it != end; it = d->cells.remove(it))
  543. {
  544. delete *it;
  545. }
  546. }
  547. TQRect Region::boundingRect() const
  548. {
  549. int left = KS_colMax;
  550. int right = 1;
  551. int top = KS_rowMax;
  552. int bottom = 1;
  553. Region::ConstIterator endOfList = cells().constEnd();
  554. for (Region::ConstIterator it = cells().constBegin(); it != endOfList; ++it)
  555. {
  556. TQRect range = (*it)->rect().normalize();
  557. if (range.left() < left)
  558. {
  559. left = range.left();
  560. }
  561. if (range.right() > right)
  562. {
  563. right = range.right();
  564. }
  565. if (range.top() < top)
  566. {
  567. top = range.top();
  568. }
  569. if (range.bottom() > bottom)
  570. {
  571. bottom = range.bottom();
  572. }
  573. }
  574. return TQRect(left, top, right-left+1, bottom-top+1);
  575. }
  576. Region::ConstIterator Region::constBegin() const
  577. {
  578. return d->cells.constBegin();
  579. }
  580. Region::ConstIterator Region::constEnd() const
  581. {
  582. return d->cells.constEnd();
  583. }
  584. TQValueList<Region::Element*>& Region::cells() const
  585. {
  586. return d->cells;
  587. }
  588. bool Region::operator==(const Region& other) const
  589. {
  590. ConstIterator endOfList(d->cells.constEnd());
  591. ConstIterator endOfOtherList(other.d->cells.constEnd());
  592. ConstIterator it = d->cells.constBegin();
  593. ConstIterator it2 = other.d->cells.constBegin();
  594. while (it != endOfList && it2 != endOfOtherList)
  595. {
  596. if ((*it++)->rect() != (*it2++)->rect())
  597. {
  598. return false;
  599. }
  600. }
  601. return true;
  602. }
  603. void Region::operator=(const Region& other)
  604. {
  605. d->view = other.d->view;
  606. clear();
  607. ConstIterator end(other.d->cells.constEnd());
  608. for (ConstIterator it = other.d->cells.constBegin(); it != end; ++it)
  609. {
  610. Element *element = *it;
  611. if (element->type() == Element::Point)
  612. {
  613. Point* point = static_cast<Point*>(element);
  614. d->cells.append(createPoint(*point));
  615. }
  616. else
  617. {
  618. Range* range = static_cast<Range*>(element);
  619. d->cells.append(createRange(*range));
  620. }
  621. }
  622. }
  623. Sheet* Region::filterSheetName(TQString& sRegion)
  624. {
  625. Sheet* sheet = 0;
  626. int delimiterPos = sRegion.find( '!' );
  627. if (delimiterPos > -1)
  628. {
  629. TQString sheetName = sRegion.left(delimiterPos);
  630. // remove the '!'
  631. sRegion = sRegion.right(sRegion.length() - delimiterPos - 1);
  632. sheet = d->view->doc()->map()->findSheet(sheetName);
  633. if (!sheet)
  634. {
  635. kdDebug() << "Sheet " << sheetName << " not found. Using active sheet!" << endl;
  636. sheet = d->view->activeSheet();
  637. }
  638. }
  639. return sheet;
  640. }
  641. Region::Point* Region::createPoint(const TQPoint& point) const
  642. {
  643. return new Point(point);
  644. }
  645. Region::Point* Region::createPoint(const TQString& string) const
  646. {
  647. return new Point(string);
  648. }
  649. Region::Point* Region::createPoint(const Point& point) const
  650. {
  651. return new Point(point);
  652. }
  653. Region::Range* Region::createRange(const TQRect& rect) const
  654. {
  655. return new Range(rect);
  656. }
  657. Region::Range* Region::createRange(const TQString& string) const
  658. {
  659. return new Range(string);
  660. }
  661. Region::Range* Region::createRange(const Range& range) const
  662. {
  663. return new Range(range);
  664. }
  665. /***************************************************************************
  666. class Element
  667. ****************************************************************************/
  668. Region::Element::Element()
  669. : m_sheet(0)
  670. {
  671. }
  672. Region::Element::~Element()
  673. {
  674. }
  675. /***************************************************************************
  676. class Point
  677. ****************************************************************************/
  678. Region::Point::Point(const TQPoint& point)
  679. : Region::Element(),
  680. m_point(point)
  681. {
  682. }
  683. Region::Point::Point(const TQString& sCell)
  684. : Region::Element(),
  685. m_point()
  686. {
  687. uint length = sCell.length();
  688. if (length == 0)
  689. {
  690. kdDebug(36001) << "Region::Point::init: length = 0" << endl;
  691. return;
  692. }
  693. TQString string = sCell;//Region::filterSheetName(sCell);
  694. uint p = 0;
  695. // Fixed ?
  696. if (string[0] == '$')
  697. {
  698. p++;
  699. }
  700. // Malformed ?
  701. if (p == length)
  702. {
  703. kdDebug(36001) << "Region::Point::init: no point after '$' (string: '" << string.mid(p) << "'" << endl;
  704. return;
  705. }
  706. if (string[p] < 'A' || string[p] > 'Z')
  707. {
  708. if (string[p] < 'a' || string[p] > 'z')
  709. {
  710. kdDebug(36001) << "Region::Point::init: wrong first character in point (string: '" << string.mid(p) << "'" << endl;
  711. return;
  712. }
  713. }
  714. //default is error
  715. int x = -1;
  716. //search for the first character != text
  717. int result = string.find( TQRegExp("[^A-Za-z]+"), p );
  718. //get the colomn number for the character between actual position and the first non text charakter
  719. if ( result != -1 )
  720. {
  721. x = util_decodeColumnLabelText( string.mid( p, result - p ) ); // x is defined now
  722. }
  723. else // If there isn't any, then this is not a point -> return
  724. {
  725. kdDebug(36001) << "Region::Point::init: no number in string (string: '" << string.mid( p, result ) << "'" << endl;
  726. return;
  727. }
  728. p = result;
  729. //limit is KS_colMax
  730. if ( x > KS_colMax )
  731. {
  732. kdDebug(36001) << "Region::Point::init: column value too high (col: " << x << ")" << endl;
  733. return;
  734. }
  735. // Malformed ?
  736. if (p == length)
  737. {
  738. kdDebug(36001) << "Region::Point::init: p==length after cols" << endl;
  739. return;
  740. }
  741. if (string[p] == '$')
  742. {
  743. p++;
  744. // Malformed ?
  745. if ( p == length )
  746. {
  747. kdDebug(36001) << "Region::Point::init: p==length after $ of row" << endl;
  748. return;
  749. }
  750. }
  751. uint p2 = p;
  752. while ( p < length )
  753. {
  754. if (!TQChar(string[p++]).isDigit())
  755. {
  756. kdDebug(36001) << "Region::Point::init: no number" << endl;
  757. return;
  758. }
  759. }
  760. bool ok;
  761. int y = string.mid( p2, p-p2 ).toInt( &ok );
  762. if ( !ok )
  763. {
  764. kdDebug(36001) << "Region::Point::init: Invalid number (string: '" << string.mid( p2, p-p2 ) << "'" << endl;
  765. return;
  766. }
  767. if ( y > KS_rowMax )
  768. {
  769. kdDebug(36001) << "Region::Point::init: row value too high (row: " << y << ")" << endl;
  770. return;
  771. }
  772. if ( y <= 0 )
  773. {
  774. kdDebug(36001) << "Region::Point::init: y <= 0" << endl;
  775. return;
  776. }
  777. m_point = TQPoint(x, y);
  778. }
  779. Region::Point::~Point()
  780. {
  781. }
  782. TQString Region::Point::name(Sheet* originSheet) const
  783. {
  784. TQString name = "";
  785. if (m_sheet && m_sheet != originSheet)
  786. {
  787. name = m_sheet->sheetName() + "!";
  788. }
  789. return name + Cell::name(m_point.x(), m_point.y());
  790. }
  791. bool Region::Point::contains(const TQPoint& point) const
  792. {
  793. return (m_point == point);
  794. }
  795. bool Region::Point::contains(const TQRect& range) const
  796. {
  797. return (range.width() == 1) && (range.height() == 1) && (range.topLeft() == m_point);
  798. }
  799. /***************************************************************************
  800. class Range
  801. ****************************************************************************/
  802. Region::Range::Range(const TQRect& rect)
  803. : Region::Element(),
  804. m_range(rect)
  805. {
  806. }
  807. Region::Range::Range(const TQString& sRange)
  808. : Region::Element(),
  809. m_range()
  810. {
  811. int delimiterPos = sRange.find(':');
  812. if (delimiterPos == -1)
  813. {
  814. return;
  815. }
  816. //Region::filterSheetName(sRange);
  817. Region::Point ul(sRange.left(delimiterPos));
  818. Region::Point lr(sRange.mid(delimiterPos + 1));
  819. if (!ul.isValid() || !lr.isValid())
  820. {
  821. return;
  822. }
  823. m_range = TQRect(ul.pos(), lr.pos());
  824. }
  825. Region::Range::~Range()
  826. {
  827. }
  828. TQString Region::Range::name(Sheet* originSheet) const
  829. {
  830. TQString name = "";
  831. if (m_sheet && m_sheet != originSheet)
  832. {
  833. name = m_sheet->sheetName() + "!";
  834. }
  835. return name + Cell::name(m_range.left(), m_range.top()) + ":" +
  836. Cell::name(m_range.right(), m_range.bottom() );
  837. }
  838. bool Region::Range::contains(const TQPoint& point) const
  839. {
  840. return m_range.normalize().contains(point);
  841. }
  842. bool Region::Range::contains(const TQRect& range) const
  843. {
  844. return m_range.normalize().contains(range.normalize());
  845. }
  846. } // namespace KSpread