summaryrefslogtreecommitdiffstats
path: root/src/listviewcomparison.h
blob: 4c0ed4344b2b0be557ab94bed82d125e0658426e (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 <qregexp.h>

class QStringList;
class QIconViewItem;

namespace Tellico {
  namespace GUI {
    class ListViewItem;
  }

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

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

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

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

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

private:
  QString m_fieldName;
};

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

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

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

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

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

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

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

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

private:
  int compareLCC(const QStringList& cap1, const QStringList& cap2) const;
  QRegExp 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 QIconViewItem* item1, const QIconViewItem* item2);

protected:
  virtual int compare(const QString&, const QString&) { 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 QIconViewItem* item1, const QIconViewItem* item2);

private:
  QPtrList<ListViewComparison> m_comparisons;
};

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

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

}
#endif