summaryrefslogtreecommitdiffstats
path: root/src/listviewcomparison.h
blob: 28a38783edef953024f7dc72e3aa093ff0166b09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***************************************************************************
    copyright            : (C) 2007 by Robby Stephenson
    email                : robby@periapsis.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#ifndef TELLICO_LISTVIEWCOMPARISON_H
#define TELLICO_LISTVIEWCOMPARISON_H

#include "datavectors.h"

#include <tqregexp.h>

class TQStringList;
class TQIconViewItem;

namespace Tellico {
  namespace GUI {
    class ListViewItem;
  }

class ListViewComparison {
public:
  ListViewComparison(Data::ConstFieldPtr field);
  virtual ~ListViewComparison() {}

  const TQString& fieldName() const { return m_fieldName; }

  virtual int compare(int col, const GUI::ListViewItem* item1, const GUI::ListViewItem* item2, bool asc);
  virtual int compare(const TQIconViewItem* item1, const TQIconViewItem* item2);

  static ListViewComparison* create(Data::FieldPtr field);
  static ListViewComparison* create(Data::ConstFieldPtr field);

protected:
  virtual int compare(const TQString& str1, const TQString& str2) = 0;

private:
  TQString m_fieldName;
};

class StringComparison : public ListViewComparison {
public:
  StringComparison(Data::ConstFieldPtr field);

protected:
  virtual int compare(const TQString& str1, const TQString& str2);
};

class TitleComparison : public ListViewComparison {
public:
  TitleComparison(Data::ConstFieldPtr field);

protected:
  virtual int compare(const TQString& str1, const TQString& str2);
};

class NumberComparison : public ListViewComparison {
public:
  NumberComparison(Data::ConstFieldPtr field);

protected:
  virtual int compare(const TQString& str1, const TQString& str2);
};

class LCCComparison : public StringComparison {
public:
  LCCComparison(Data::ConstFieldPtr field);

protected:
  virtual int compare(const TQString& str1, const TQString& str2);

private:
  int compareLCC(const TQStringList& cap1, const TQStringList& cap2) const;
  TQRegExp m_regexp;
};

class PixmapComparison : public ListViewComparison {
public:
  PixmapComparison(Data::ConstFieldPtr field);

  virtual int compare(int col, const GUI::ListViewItem* item1, const GUI::ListViewItem* item2, bool asc);
  virtual int compare(const TQIconViewItem* item1, const TQIconViewItem* item2);

protected:
  virtual int compare(const TQString&, const TQString&) { return 0; }
};

class DependentComparison : public StringComparison {
public:
  DependentComparison(Data::ConstFieldPtr field);

  virtual int compare(int col, const GUI::ListViewItem* item1, const GUI::ListViewItem* item2, bool asc);
  virtual int compare(const TQIconViewItem* item1, const TQIconViewItem* item2);

private:
  TQPtrList<ListViewComparison> m_comparisons;
};

class ISODateComparison : public ListViewComparison {
public:
  ISODateComparison(Data::ConstFieldPtr field);

protected:
  virtual int compare(const TQString& str1, const TQString& str2);
};

}
#endif