-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathCondFormat.h
More file actions
81 lines (65 loc) · 2.68 KB
/
CondFormat.h
File metadata and controls
81 lines (65 loc) · 2.68 KB
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
#ifndef CONDFORMAT_H
#define CONDFORMAT_H
#include <QString>
#include <QColor>
#include <QFont>
#include <QModelIndex>
class QAbstractTableModel;
// Conditional formatting for given format to table cells based on a specified condition.
class CondFormat
{
public:
enum Alignment {
AlignLeft = 0,
AlignRight,
AlignCenter,
AlignJustify
};
// List of alignment texts. Order must be as Alignment definition above.
static QStringList alignmentTexts() {
return {QObject::tr("Left"), QObject::tr("Right"), QObject::tr("Center"), QObject::tr("Justify")};
}
// Get alignment from combined Qt alignment (note that this will lose any combination of our Alignment enum
// with other values present in the flag (e.g. vertical alignment).
static Alignment fromCombinedAlignment(Qt::Alignment align);
CondFormat() {}
CondFormat(const QString& filter,
const QColor& foreground,
const QColor& background,
const QFont& font,
const Alignment alignment = AlignLeft,
const QString& encoding = QString());
// Create a new CondFormat from values obtained from the model
CondFormat(const QString& filter,
const QAbstractTableModel* model,
const QModelIndex index,
const QString& encoding = QString());
static std::string filterToSqlCondition(const QString& value, const QString& encoding = QString());
private:
std::string m_sqlCondition;
QString m_filter;
QColor m_bgColor;
QColor m_fgColor;
QFont m_font;
Alignment m_align;
public:
std::string sqlCondition() const { return m_sqlCondition; }
QString filter() const { return m_filter; }
QColor backgroundColor() const { return m_bgColor; }
QColor foregroundColor() const { return m_fgColor; }
void setBackgroundColor(QColor color) { m_bgColor = color; }
void setForegroundColor(QColor color) { m_fgColor = color; }
bool isBold() const { return m_font.bold(); }
bool isItalic() const { return m_font.italic(); }
bool isUnderline() const { return m_font.underline(); }
void setBold(bool value) { m_font.setBold(value); }
void setItalic(bool value) { m_font.setItalic(value); }
void setUnderline(bool value) { m_font.setUnderline(value); }
QFont font() const { return m_font; }
void setFontFamily(const QString &family) { m_font.setFamily(family); }
void setFontPointSize(int pointSize) { m_font.setPointSize(pointSize); }
Alignment alignment() const { return m_align; }
void setAlignment(Alignment value) { m_align = value; }
Qt::AlignmentFlag alignmentFlag() const;
};
#endif // CONDFORMAT_H