Skip to content

Commit

Permalink
Remove some unnecessary includes
Browse files Browse the repository at this point in the history
  • Loading branch information
MKleusberg committed Apr 29, 2019
1 parent f821fbb commit 189652d
Show file tree
Hide file tree
Showing 32 changed files with 200 additions and 162 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/AddRecordDialog.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef ADDRECORDDIALOG_H
#define ADDRECORDDIALOG_H

#include "sql/sqlitetypes.h"
#include "sql/ObjectIdentifier.h"

#include <QDialog>

Expand Down
2 changes: 1 addition & 1 deletion src/ColumnDisplayFormatDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions src/ColumnDisplayFormatDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/DotenvFormat.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef DOTENVFORMAT_H
#define DOTENVFORMAT_H

#include <QIODevice>
#include <QSettings>

class QIODevice;

class DotenvFormat
{
public:
Expand Down
1 change: 1 addition & 0 deletions src/EditIndexDialog.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef EDITINDEXDIALOG_H
#define EDITINDEXDIALOG_H

#include "sql/ObjectIdentifier.h"
#include "sql/sqlitetypes.h"

#include <QDialog>
Expand Down
1 change: 1 addition & 0 deletions src/EditTableDialog.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef EDITTABLEDIALOG_H
#define EDITTABLEDIALOG_H

#include "sql/ObjectIdentifier.h"
#include "sql/sqlitetypes.h"

#include <QDialog>
Expand Down
2 changes: 1 addition & 1 deletion src/ExportDataDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <QDialog>

#include "sql/sqlitetypes.h"
#include "sql/ObjectIdentifier.h"

class DBBrowserDB;

Expand Down
5 changes: 3 additions & 2 deletions src/ExtendedTableWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

#include <QTableView>
#include <QSet>
#include <QDropEvent>
#include <QDragMoveEvent>
#include <QStyledItemDelegate>
#include <QSortFilterProxyModel>

#include "sql/Query.h"

class QMenu;
class QMimeData;
class QDropEvent;
class QDragMoveEvent;

class FilterTableHeader;
namespace sqlb { class ObjectIdentifier; }

Expand Down
1 change: 0 additions & 1 deletion src/FilterTableHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QHeaderView>
#include <vector>

class QLineEdit;
class QTableView;
class FilterLineEdit;

Expand Down
3 changes: 2 additions & 1 deletion src/FindReplaceDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define FindReplaceDialog_H

#include <QDialog>
#include <QAbstractButton>

class QAbstractButton;

class ExtendedScintilla;

Expand Down
3 changes: 0 additions & 3 deletions src/ForeignKeyEditorDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include <string>

class DBBrowserDB;
class QPushButton;
class QComboBox;
class QLineEdit;

namespace sqlb
{
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "Palette.h"
#include "CondFormat.h"
#include "sql/Query.h"
#include "RunSql.h"

#include <memory>
#include <QMainWindow>
Expand All @@ -19,6 +18,7 @@ class RemoteDock;
class RemoteDatabase;
class FindReplaceDialog;
class ExtendedTableWidget;
class RunSql;

class QDragEnterEvent;
class QIntValidator;
Expand Down
7 changes: 4 additions & 3 deletions src/PlotDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

#include <QDialog>
#include <QVariant>
#include <QMenu>

class SqliteTableModel;
class QTreeWidgetItem;
class QMenu;
class QPrinter;
class QTreeWidgetItem;

class SqliteTableModel;
struct BrowseDataTableSettings;

namespace Ui {
Expand Down
1 change: 0 additions & 1 deletion src/PreferencesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define PREFERENCESDIALOG_H

#include <QDialog>
#include <QVariant>

class QTreeWidgetItem;
class QFrame;
Expand Down
2 changes: 0 additions & 2 deletions src/RemoteDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

class QNetworkAccessManager;
class QNetworkConfigurationManager;
class QString;
class QNetworkReply;
class QSslError;
class QProgressDialog;
class QNetworkRequest;
class QHttpMultiPart;
Expand Down
3 changes: 2 additions & 1 deletion src/RowLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include <QString>
#include <QMutex>

#include "sqlite.h"
#include "RowCache.h"

class sqlite3;

class RowLoader : public QThread
{
Q_OBJECT
Expand Down
2 changes: 2 additions & 0 deletions src/docktextedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/docktextedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions src/sql/ObjectIdentifier.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

}
98 changes: 98 additions & 0 deletions src/sql/ObjectIdentifier.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/sql/Query.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef QUERY_H
#define QUERY_H

#include "sqlitetypes.h"
#include "ObjectIdentifier.h"

#include <string>
#include <unordered_map>
Expand Down
Loading

0 comments on commit 189652d

Please sign in to comment.