Remove some unnecessary includes

This commit is contained in:
Martin Kleusberg
2019-04-29 20:54:26 +02:00
parent f821fbb1a8
commit 189652d350
32 changed files with 200 additions and 162 deletions

View File

@@ -104,6 +104,7 @@ set(SQLB_HDR
src/version.h
src/sql/sqlitetypes.h
src/sql/Query.h
src/sql/ObjectIdentifier.h
src/csvparser.h
src/sqlite.h
src/grammar/sqlite3TokenTypes.hpp
@@ -178,6 +179,7 @@ set(SQLB_SRC
src/RowLoader.cpp
src/sql/sqlitetypes.cpp
src/sql/Query.cpp
src/sql/ObjectIdentifier.cpp
src/sqltextedit.cpp
src/docktextedit.cpp
src/csvparser.cpp

View File

@@ -1,7 +1,7 @@
#ifndef ADDRECORDDIALOG_H
#define ADDRECORDDIALOG_H
#include "sql/sqlitetypes.h"
#include "sql/ObjectIdentifier.h"
#include <QDialog>

View File

@@ -5,7 +5,7 @@
#include "sql/sqlitetypes.h"
#include "sqlitedb.h"
ColumnDisplayFormatDialog::ColumnDisplayFormatDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, const QString& colname, QString current_format, QWidget* parent)
ColumnDisplayFormatDialog::ColumnDisplayFormatDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, const QString& colname, const QString& current_format, QWidget* parent)
: QDialog(parent),
ui(new Ui::ColumnDisplayFormatDialog),
column_name(colname),

View File

@@ -2,10 +2,11 @@
#define COLUMNDISPLAYFORMATDIALOG_H
#include <QDialog>
#include <QString>
#include <QMap>
#include "sql/sqlitetypes.h"
#include "sql/ObjectIdentifier.h"
class QString;
class DBBrowserDB;
@@ -18,7 +19,7 @@ class ColumnDisplayFormatDialog : public QDialog
Q_OBJECT
public:
explicit ColumnDisplayFormatDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, const QString& colname, QString current_format, QWidget* parent = nullptr);
explicit ColumnDisplayFormatDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, const QString& colname, const QString& current_format, QWidget* parent = nullptr);
~ColumnDisplayFormatDialog() override;
QString selectedDisplayFormat() const;

View File

@@ -1,9 +1,10 @@
#ifndef DOTENVFORMAT_H
#define DOTENVFORMAT_H
#include <QIODevice>
#include <QSettings>
class QIODevice;
class DotenvFormat
{
public:

View File

@@ -1,6 +1,7 @@
#ifndef EDITINDEXDIALOG_H
#define EDITINDEXDIALOG_H
#include "sql/ObjectIdentifier.h"
#include "sql/sqlitetypes.h"
#include <QDialog>

View File

@@ -1,6 +1,7 @@
#ifndef EDITTABLEDIALOG_H
#define EDITTABLEDIALOG_H
#include "sql/ObjectIdentifier.h"
#include "sql/sqlitetypes.h"
#include <QDialog>

View File

@@ -3,7 +3,7 @@
#include <QDialog>
#include "sql/sqlitetypes.h"
#include "sql/ObjectIdentifier.h"
class DBBrowserDB;

View File

@@ -3,8 +3,6 @@
#include <QTableView>
#include <QSet>
#include <QDropEvent>
#include <QDragMoveEvent>
#include <QStyledItemDelegate>
#include <QSortFilterProxyModel>
@@ -12,6 +10,9 @@
class QMenu;
class QMimeData;
class QDropEvent;
class QDragMoveEvent;
class FilterTableHeader;
namespace sqlb { class ObjectIdentifier; }

View File

@@ -4,7 +4,6 @@
#include <QHeaderView>
#include <vector>
class QLineEdit;
class QTableView;
class FilterLineEdit;

View File

@@ -2,7 +2,8 @@
#define FindReplaceDialog_H
#include <QDialog>
#include <QAbstractButton>
class QAbstractButton;
class ExtendedScintilla;

View File

@@ -6,9 +6,6 @@
#include <string>
class DBBrowserDB;
class QPushButton;
class QComboBox;
class QLineEdit;
namespace sqlb
{

View File

@@ -6,7 +6,6 @@
#include "Palette.h"
#include "CondFormat.h"
#include "sql/Query.h"
#include "RunSql.h"
#include <memory>
#include <QMainWindow>
@@ -19,6 +18,7 @@ class RemoteDock;
class RemoteDatabase;
class FindReplaceDialog;
class ExtendedTableWidget;
class RunSql;
class QDragEnterEvent;
class QIntValidator;

View File

@@ -5,11 +5,12 @@
#include <QDialog>
#include <QVariant>
#include <QMenu>
class QMenu;
class QPrinter;
class QTreeWidgetItem;
class SqliteTableModel;
class QTreeWidgetItem;
class QPrinter;
struct BrowseDataTableSettings;
namespace Ui {

View File

@@ -2,7 +2,6 @@
#define PREFERENCESDIALOG_H
#include <QDialog>
#include <QVariant>
class QTreeWidgetItem;
class QFrame;

View File

@@ -6,9 +6,7 @@
class QNetworkAccessManager;
class QNetworkConfigurationManager;
class QString;
class QNetworkReply;
class QSslError;
class QProgressDialog;
class QNetworkRequest;
class QHttpMultiPart;

View File

@@ -13,9 +13,10 @@
#include <QString>
#include <QMutex>
#include "sqlite.h"
#include "RowCache.h"
class sqlite3;
class RowLoader : public QThread
{
Q_OBJECT

View File

@@ -2,6 +2,8 @@
#include "Settings.h"
#include <Qsci/qscistyle.h>
#include <Qsci/qscilexerjson.h>
#include <Qsci/qscilexerxml.h>
QsciLexerJSON* DockTextEdit::jsonLexer = nullptr;
QsciLexerXML* DockTextEdit::xmlLexer = nullptr;

View File

@@ -2,8 +2,9 @@
#define DOCKTEXTEDIT_H
#include "ExtendedScintilla.h"
#include <Qsci/qscilexerjson.h>
#include <Qsci/qscilexerxml.h>
class QsciLexerJSON;
class QsciLexerXML;
/**
* @brief The DockTextEdit class

View File

@@ -0,0 +1,52 @@
#include "ObjectIdentifier.h"
#include <regex>
namespace sqlb {
static escapeQuoting customQuoting = DoubleQuotes;
void setIdentifierQuoting(escapeQuoting toQuoting)
{
customQuoting = toQuoting;
}
std::string escapeIdentifier(const std::string& id)
{
switch(customQuoting) {
case GraveAccents:
return '`' + std::regex_replace(id, std::regex("\\`"), "``") + '`';
case SquareBrackets:
// There aren't any escaping possibilities for square brackets inside the identifier,
// so we rely on the user to not enter these characters when this kind of quoting is
// selected.
return '[' + id + ']';
case DoubleQuotes:
default:
// This may produce a 'control reaches end of non-void function' warning if the
// default branch is removed, even though we have covered all possibilities in the
// switch statement.
return '"' + std::regex_replace(id, std::regex("\\\""), "\"\"") + '"';
}
}
bool ObjectIdentifier::fromSerialised(const std::string& serialised)
{
auto pos_comma = serialised.find(",");
auto pos_colon = serialised.find(":");
if(pos_comma == serialised.npos || pos_colon == serialised.npos)
return false;
size_t size_schema, size_name;
size_schema = std::stoul(serialised.substr(0, pos_comma));
size_name = std::stoul(serialised.substr(pos_comma+1, pos_colon-pos_comma));
if(pos_colon + size_schema + size_name + 1 != serialised.size())
return false;
m_schema = serialised.substr(pos_colon + 1, size_schema);
m_name = serialised.substr(pos_colon + size_schema + 1, size_name);
return true;
}
}

View File

@@ -0,0 +1,98 @@
#ifndef OBJECTIDENTIFIER_H
#define OBJECTIDENTIFIER_H
#include <string>
namespace sqlb {
enum escapeQuoting {
DoubleQuotes,
GraveAccents,
SquareBrackets
};
// Set quoting style for escapeIdentifier
void setIdentifierQuoting(escapeQuoting toQuoting);
// Add quotes to an identifier
std::string escapeIdentifier(const std::string& id);
// Object identifier consisting of schema name and object name
class ObjectIdentifier
{
public:
ObjectIdentifier(const std::string& schema, const std::string& name)
: m_schema(schema),
m_name(name)
{
}
ObjectIdentifier()
: m_schema("main")
{
}
explicit ObjectIdentifier(const std::string& variant)
{
// Try to unserialise the parameter first. If that does not work, just assume it's an object name for the main schema
clear();
if(!fromSerialised(variant))
m_name = variant;
}
bool operator==(const ObjectIdentifier& rhs) const
{
return (rhs.m_schema == m_schema && rhs.m_name == m_name);
}
bool operator<(const ObjectIdentifier& rhs) const
{
return toDisplayString() < rhs.toDisplayString();
}
const std::string& schema() const { return m_schema; }
const std::string& name() const { return m_name; }
void setSchema(const std::string& schema) { m_schema = schema; }
void setName(const std::string& name) { m_name = name; }
void clear()
{
m_schema = "main";
m_name.clear();
}
bool isEmpty() const { return m_name.empty(); }
// This returns a string which can be used in SQL statements
std::string toString(bool shortName = false) const
{
if(shortName && m_schema == "main")
return sqlb::escapeIdentifier(m_name);
else
return sqlb::escapeIdentifier(m_schema) + "." + sqlb::escapeIdentifier(m_name);
}
// This returns a string which can be used in the user interface
std::string toDisplayString() const
{
if(m_schema == "main")
return m_name;
else
return m_schema + "." + m_name;
}
std::string toSerialised() const
{
return std::to_string(m_schema.size()) + "," + std::to_string(m_name.size()) + ":" + m_schema + m_name;
}
bool fromSerialised(const std::string& serialised);
private:
std::string m_schema;
std::string m_name;
};
}
#endif

View File

@@ -1,7 +1,7 @@
#ifndef QUERY_H
#define QUERY_H
#include "sqlitetypes.h"
#include "ObjectIdentifier.h"
#include <string>
#include <unordered_map>

View File

@@ -1,4 +1,5 @@
#include "sqlitetypes.h"
#include "ObjectIdentifier.h"
#include "grammar/Sqlite3Lexer.hpp"
#include "grammar/Sqlite3Parser.hpp"
@@ -10,32 +11,6 @@
namespace sqlb {
static escapeQuoting customQuoting = DoubleQuotes;
void setIdentifierQuoting(escapeQuoting toQuoting)
{
customQuoting = toQuoting;
}
std::string escapeIdentifier(std::string id)
{
switch(customQuoting) {
case GraveAccents:
return '`' + std::regex_replace(id, std::regex("\\`"), "``") + '`';
case SquareBrackets:
// There aren't any escaping possibilities for square brackets inside the identifier,
// so we rely on the user to not enter these characters when this kind of quoting is
// selected.
return '[' + id + ']';
case DoubleQuotes:
default:
// This may produce a 'control reaches end of non-void function' warning if the
// default branch is removed, even though we have covered all possibilities in the
// switch statement.
return '"' + std::regex_replace(id, std::regex("\\\""), "\"\"") + '"';
}
}
StringVector escapeIdentifier(StringVector ids)
{
std::transform(ids.begin(), ids.end(), ids.begin(), [](const std::string& id) {

View File

@@ -2,10 +2,11 @@
#ifndef SQLITETYPES_H
#define SQLITETYPES_H
#include <vector>
#include <unordered_map>
#include <memory>
#include <algorithm>
#include <memory>
#include <unordered_map>
#include <string>
#include <vector>
template<typename C, typename E>
bool contains(const C& container, E element)
@@ -24,114 +25,11 @@ bool compare_ci(const T& a, const T& b)
namespace sqlb {
enum escapeQuoting {
DoubleQuotes,
GraveAccents,
SquareBrackets
};
using StringVector = std::vector<std::string>;
// Set quoting style for escapeIdentifier
void setIdentifierQuoting(escapeQuoting toQuoting);
std::string escapeIdentifier(std::string id);
StringVector escapeIdentifier(StringVector ids);
std::string joinStringVector(const StringVector& vec, const std::string& delim);
class ObjectIdentifier
{
public:
ObjectIdentifier(const std::string& schema, const std::string& name)
: m_schema(schema),
m_name(name)
{
}
ObjectIdentifier()
: m_schema("main")
{
}
explicit ObjectIdentifier(const std::string& variant)
{
// Try to unserialise the parameter first. If that does not work, just assume it's an object name for the main schema
clear();
if(!fromSerialised(variant))
m_name = variant;
}
bool operator==(const ObjectIdentifier& rhs) const
{
return (rhs.m_schema == m_schema && rhs.m_name == m_name);
}
bool operator<(const ObjectIdentifier& rhs) const
{
return toDisplayString() < rhs.toDisplayString();
}
const std::string& schema() const { return m_schema; }
const std::string& name() const { return m_name; }
void setSchema(const std::string& schema) { m_schema = schema; }
void setName(const std::string& name) { m_name = name; }
void clear()
{
m_schema = "main";
m_name.clear();
}
bool isEmpty() const { return m_name.empty(); }
// This returns a string which can be used in SQL statements
std::string toString(bool shortName = false) const
{
if(shortName && m_schema == "main")
return sqlb::escapeIdentifier(m_name);
else
return sqlb::escapeIdentifier(m_schema) + "." + sqlb::escapeIdentifier(m_name);
}
// This returns a string which can be used in the user interface
std::string toDisplayString() const
{
if(m_schema == "main")
return m_name;
else
return m_schema + "." + m_name;
}
std::string toSerialised() const
{
return std::to_string(m_schema.size()) + "," + std::to_string(m_name.size()) + ":" + m_schema + m_name;
}
bool fromSerialised(const std::string& serialised)
{
auto pos_comma = serialised.find(",");
auto pos_colon = serialised.find(":");
if(pos_comma == serialised.npos || pos_colon == serialised.npos)
return false;
size_t size_schema, size_name;
size_schema = std::stoul(serialised.substr(0, pos_comma));
size_name = std::stoul(serialised.substr(pos_comma+1, pos_colon-pos_comma));
if(pos_colon + size_schema + size_name + 1 != serialised.size())
return false;
m_schema = serialised.substr(pos_colon + 1, size_schema);
m_name = serialised.substr(pos_colon + size_schema + 1, size_name);
return true;
}
private:
std::string m_schema;
std::string m_name;
};
struct StringVectorHash
{
size_t operator()(const StringVector& key) const

View File

@@ -1,6 +1,7 @@
#ifndef SQLITEDB_H
#define SQLITEDB_H
#include "sql/ObjectIdentifier.h"
#include "sql/sqlitetypes.h"
#include <condition_variable>

View File

@@ -3,6 +3,7 @@
#include "sqlite.h"
#include "Settings.h"
#include "Data.h"
#include "CondFormat.h"
#include <QMessageBox>
#include <QApplication>

View File

@@ -8,11 +8,12 @@
#include <vector>
#include "RowCache.h"
#include "CondFormat.h"
#include "sql/Query.h"
#include "sql/sqlitetypes.h"
struct sqlite3;
class DBBrowserDB;
class CondFormat;
class SqliteTableModel : public QAbstractTableModel
{

View File

@@ -1,4 +1,4 @@
#include "sql/sqlitetypes.h"
#include "sql/ObjectIdentifier.h"
#include "sqltextedit.h"
#include "Settings.h"
#include "SqlUiLexer.h"

View File

@@ -3,7 +3,6 @@
#include "ExtendedScintilla.h"
class FindReplaceDialog;
class SqlUiLexer;
/**

View File

@@ -73,7 +73,8 @@ HEADERS += \
Palette.h \
CondFormat.h \
sql/Query.h \
RunSql.h
RunSql.h \
sql/ObjectIdentifier.h
SOURCES += \
sqlitedb.cpp \
@@ -123,7 +124,8 @@ SOURCES += \
Palette.cpp \
CondFormat.cpp \
sql/Query.cpp \
RunSql.cpp
RunSql.cpp \
sql/ObjectIdentifier.cpp
RESOURCES += icons/icons.qrc \
translations/flags/flags.qrc \

View File

@@ -12,6 +12,7 @@ set(TESTSQLOBJECTS_SRC
../RowLoader.cpp
../sql/sqlitetypes.cpp
../sql/Query.cpp
../sql/ObjectIdentifier.cpp
../csvparser.cpp
../grammar/Sqlite3Lexer.cpp
../grammar/Sqlite3Parser.cpp
@@ -29,6 +30,7 @@ set(TESTSQLOBJECTS_HDR
../grammar/Sqlite3Parser.hpp
../sql/sqlitetypes.h
../sql/Query.h
../sql/ObjectIdentifier.h
../Data.h
)
@@ -98,6 +100,7 @@ set(TESTREGEX_SRC
../RowLoader.cpp
../sql/sqlitetypes.cpp
../sql/Query.cpp
../sql/ObjectIdentifier.cpp
../grammar/Sqlite3Lexer.cpp
../grammar/Sqlite3Parser.cpp
../Settings.cpp
@@ -114,6 +117,7 @@ set(TESTREGEX_HDR
../grammar/Sqlite3Parser.hpp
../sql/sqlitetypes.h
../sql/Query.h
../sql/ObjectIdentifier.h
../Data.h
)

View File

@@ -1,4 +1,5 @@
#include "testsqlobjects.h"
#include "../sql/ObjectIdentifier.h"
#include "../sql/sqlitetypes.h"
#include <QtTest/QtTest>