aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/expectedtoken.h
blob: 9242dd807b20b83380500942e6f4aad738a8a507 (plain) (blame)
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
#ifndef EXPECTEDTOKEN_H
#define EXPECTEDTOKEN_H

#include "coreSQLiteStudio_global.h"
#include <QString>
#include <QSharedPointer>

struct API_EXPORT ExpectedToken
{
    /**
     * @brief The expected token type
     * Order of this enum matters, because it defines the order
     * of sorting a list of expected tokens by CompletionComparer.
     * The NO_VALUE value means that there is no prepared value,
     * but some context information and/or label is available.
     */
    enum Type
    {
        COLUMN,
        TABLE,
        INDEX,
        TRIGGER,
        VIEW,
        DATABASE,
        NO_VALUE,
        KEYWORD,
        FUNCTION,
        OPERATOR,
        COLLATION,
        PRAGMA,
        STRING,
        NUMBER,
        BLOB,
        OTHER
    };

    /**
     * @brief type Token type.
     */
    Type type;

    /**
     * @brief value Token value.
     * The actual value to be inserted in expected position.
     */
    QString value;

    /**
     * @brief contextInfo Context information.
     * Context of proposed token. Context is for example table, that proposed column belongs to,
     * or it's database, that proposed table belongs to. This is used when completer sorts results.
     */
    QString contextInfo;

    /**
     * @brief label Token explanation label.
     * This is a context info to be displayed in completer. It may provide info about actual object under the alias,
     * or human readable info about the proposed token (like "New column name").
     */
    QString label;

    /**
     * @brief prefix Token prefix.
     * Necessary prefix for token to be valid. It should be concatenated with the value using a dot character.
     */
    QString prefix;

    /**
     * @brief Token priority on completion list.
     *
     * Some tokens require manual control on where they appear in the completion list. If this value is any positive
     * number, than it's considered as a priority. The higher value, the higher priority. 0 and negative numbers are ignored.
     * The priority has a precedence before any other sorting rules.
     */
    int priority = 0;

    /**
     * @brief needsWrapping Tells if the token requires wrapping.
     * @return true if the token is of type that might require wrapping (in case the value contains forbidden characters or keyword as a name).
     */
    bool needsWrapping() const;

    int operator==(const ExpectedToken& other);
    QString toString() const;
};

/**
 * @brief The ExpectedTokenPtr class
 * This class would normally be just a typedef, but we need qHash() functionality
 * being applied for this type, so simple typedef wouldn't overwrite the type matching for qHash() arguments.
 * The qHash() is necessary for QSet and we need that for getting rid of duplicates.
 */
class API_EXPORT ExpectedTokenPtr : public QSharedPointer<ExpectedToken>
{
    public:
        ExpectedTokenPtr();
        explicit ExpectedTokenPtr(ExpectedToken* ptr);
        explicit ExpectedTokenPtr(const QSharedPointer<ExpectedToken> & other);
        explicit ExpectedTokenPtr(const QWeakPointer<ExpectedToken> & other);
};

int operator==(const ExpectedTokenPtr& ptr1, const ExpectedTokenPtr& ptr2);

int qHash(const ExpectedToken& token);
int qHash(const ExpectedTokenPtr &ptr);

#endif // EXPECTEDTOKEN_H