Skip to content

Commit

Permalink
compile commands generator and the beginning of database integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Beney committed Dec 31, 2018
1 parent e0853d9 commit b4503ff
Show file tree
Hide file tree
Showing 7 changed files with 1,176 additions and 103 deletions.
8 changes: 5 additions & 3 deletions VibratoNotes-Desktop.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
#-------------------------------------------------

QT += core gui widgets
QT += core gui widgets sql

TARGET = VibratoNotesDesktop
TEMPLATE = app
Expand Down Expand Up @@ -58,7 +58,8 @@ SOURCES += \
$$PWD/ui/trashitem.cpp \
$$PWD/src/ui-managers/notelist-views/trashview.cpp \
$$PWD/src/ui-managers/notelist-views/genericview.cpp \
$$PWD/ui/notebook_editparent.cpp
$$PWD/ui/notebook_editparent.cpp \
src/sql/sqlmanager.cpp

HEADERS += \
$$PWD/src/meta/info/appconfig.h \
Expand Down Expand Up @@ -96,7 +97,8 @@ HEADERS += \
$$PWD/ui/trashitem.h \
$$PWD/src/ui-managers/notelist-views/trashview.h \
$$PWD/src/ui-managers/notelist-views/genericview.h \
$$PWD/ui/notebook_editparent.h
$$PWD/ui/notebook_editparent.h \
src/sql/sqlmanager.h

INCLUDEPATH += $$PWD/include
INCLUDEPATH += $$PWD/src/models/views # Location of customlistview
Expand Down
11 changes: 11 additions & 0 deletions gen_compile_commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

mkdir -p qmake
cd qmake

if [ $1 == "clean" ]; then
make clean
rm -f ../compile_commands.json
fi

bear -a -o ../compile_commands.json $BEAR_OPTIONS make
12 changes: 12 additions & 0 deletions include/helper-io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@
#include <QFile>
#include <QJsonDocument>
#include <QMessageBox>
#include <QStandardPaths>
#include <QDir>

class HelperIO {
public:

// File/directory functions
static QDir dataDir()
{
QDir data_dir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
if ( !data_dir.exists() )
data_dir.mkpath(".");
return data_dir;
}

// Warning: Returns a char* that must be deleted.
static char *QString2CString(QString str)
{
Expand Down
100 changes: 100 additions & 0 deletions resources/dummy/notes-bkup.json

Large diffs are not rendered by default.

1,100 changes: 1,000 additions & 100 deletions resources/dummy/notes.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/sql/sqlmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "sqlmanager.h"
#include <QDir>
#include <helper-io.hpp>

SQLManager::SQLManager(QObject *parent) : QObject(parent)
{
// Create the
QDir data_dir = HelperIO::dataDir();
m_location = data_dir.filePath("vibrato-db.sql");
m_sqldb = QSqlDatabase::addDatabase("sqlite");
m_sqldb.setDatabaseName(m_location);
bool ok = m_sqldb.open();
// Die if can't connect
if (!ok) qFatal("Fatal error establishing a connection with Vibrato's sqlite3 database. :(");
}

void SQLManager::close() {
m_sqldb.close();
}

QString SQLManager::location() const
{
return m_location;
}
24 changes: 24 additions & 0 deletions src/sql/sqlmanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef SQLMANAGER_H
#define SQLMANAGER_H
#include <QObject>
#include <QSqlDatabase>

class SQLManager : public QObject
{
Q_OBJECT
public:
explicit SQLManager(QObject *parent = nullptr);
void close();

QString location() const;

signals:

public slots:

private:
QString m_location;
QSqlDatabase m_sqldb;
};

#endif // SQLMANAGER_H

0 comments on commit b4503ff

Please sign in to comment.