summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt20
-rw-r--r--README.md2
-rw-r--r--gui/CMakeLists.txt30
-rw-r--r--gui/gui.cc39
-rw-r--r--gui/gui.h26
-rw-r--r--gui/gui.ui55
-rw-r--r--gui/main.cc (renamed from src/main.cc)13
-rw-r--r--gui/resources.qrc6
-rw-r--r--gui/resources/input.txt1
-rw-r--r--inc/cache.h1
-rw-r--r--inc/dram.h1
-rw-r--r--inc/logger.h10
-rw-r--r--src/gui/gui.py0
-rw-r--r--src/logger/logger.cc20
14 files changed, 183 insertions, 41 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6a48922..9daac12 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,32 +1,34 @@
cmake_minimum_required(VERSION 3.5)
+set(CMAKE_CXX_COMPILER "g++")
project(risc_vector)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-add_compile_options(-Wall -lstdc++)
+add_compile_options(-Wall -lstdc++ -g -O0)
add_compile_options(-Wextra -Wpedantic)
# cpp standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_CXX_COMPILER "g++")
-
# header files
include_directories(
${PROJECT_SOURCE_DIR}/inc
)
+# add gui
+add_subdirectory(gui)
+
# gather source files
file(GLOB_RECURSE SRCS "src/*.cc")
-list(REMOVE_ITEM SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc")
-# find python3 components
-find_package(Python3 COMPONENTS Development REQUIRED)
+# find QT components
+find_package(Qt6 COMPONENTS Widgets REQUIRED)
+qt_standard_project_setup()
# binary executable
-add_executable(${PROJECT_NAME} ${SRCS} src/main.cc)
-target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
+add_library(${PROJECT_NAME}_lib ${SRCS})
+target_link_libraries(${PROJECT_NAME}_lib)
find_package(Catch2 REQUIRED)
@@ -35,7 +37,7 @@ file(GLOB_RECURSE TESTS "tests/*.cc")
# test executable
add_executable(tests ${SRCS} ${TESTS})
-target_link_libraries(tests PRIVATE Catch2::Catch2WithMain PRIVATE Python3::Python)
+target_link_libraries(tests PRIVATE Catch2::Catch2WithMain PRIVATE)
# test discovery
include(CTest)
diff --git a/README.md b/README.md
index 34ae8af..a6ce662 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,8 @@
## dependencies
- cmake
- g++ (GCC) 11.4.0
-- python 3.10 or newer
- catch2 version 3.5.3
+- Qt version 6.8.2
## to compile
Generate the build directory with
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
new file mode 100644
index 0000000..6b5eb22
--- /dev/null
+++ b/gui/CMakeLists.txt
@@ -0,0 +1,30 @@
+cmake_minimum_required(VERSION 3.5)
+set(CMAKE_CXX_COMPILER "g++")
+
+add_compile_options(-Wall -lstdc++)
+add_compile_options(-Wextra -Wpedantic)
+
+# cpp standard
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+# find QT components
+find_package(Qt6 COMPONENTS Widgets REQUIRED)
+qt_standard_project_setup()
+
+file(GLOB SRCS
+ "*.h"
+ "*.cc"
+ "*.ui"
+)
+
+# gather gui source files
+qt_add_resources(GUI_RESOURCES "resources.qrc")
+
+add_executable(risc_vector ${SRCS} ${GUI_RESOURCES})
+target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_lib Qt6::Widgets)
+
+set_target_properties(risc_vector PROPERTIES
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
+)
+
diff --git a/gui/gui.cc b/gui/gui.cc
new file mode 100644
index 0000000..9f2405d
--- /dev/null
+++ b/gui/gui.cc
@@ -0,0 +1,39 @@
+#include "gui.h"
+#include "ui_gui.h"
+#include <QFile>
+#include <QTextStream>
+
+Gui::Gui(QWidget *parent)
+ : QWidget(parent)
+ , ui(new Ui::gui)
+{
+ ui->setupUi(this);
+ loadTxtFile();
+}
+
+Gui::~Gui()
+{
+ delete ui;
+}
+
+void Gui::loadTxtFile(){
+ QFile inputFile(":/resources/input.txt");
+ inputFile.open(QIODevice::ReadOnly);
+
+ QTextStream in(&inputFile);
+ QString line = in.readAll();
+ inputFile.close();
+
+ ui->textEdit->setPlainText(line);
+ QTextCursor cursor = ui->textEdit->textCursor();
+ cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
+}
+
+void Gui::on_pushButton_clicked()
+{
+ QString searchString = ui->lineEdit->text();
+ ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
+}
+
+
+
diff --git a/gui/gui.h b/gui/gui.h
new file mode 100644
index 0000000..668fafa
--- /dev/null
+++ b/gui/gui.h
@@ -0,0 +1,26 @@
+#ifndef GUI_H
+#define GUI_H
+#include <QWidget>
+
+namespace Ui
+{
+class gui;
+}
+QT_END_NAMESPACE
+
+class Gui : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ Gui(QWidget *parent = nullptr);
+ ~Gui();
+
+ private slots:
+ void on_pushButton_clicked();
+
+ private:
+ Ui::gui *ui;
+ void loadTxtFile();
+};
+#endif // GUI_H
diff --git a/gui/gui.ui b/gui/gui.ui
new file mode 100644
index 0000000..5f71c91
--- /dev/null
+++ b/gui/gui.ui
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>gui</class>
+ <widget class="QWidget" name="gui">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>gui</string>
+ </property>
+ <widget class="QWidget" name="">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>30</y>
+ <width>317</width>
+ <height>232</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>keyword</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEdit"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButton">
+ <property name="text">
+ <string>find</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="textEdit"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/main.cc b/gui/main.cc
index f5eecac..4c14fbe 100644
--- a/src/main.cc
+++ b/gui/main.cc
@@ -1,6 +1,8 @@
#include "cli.h"
#include "definitions.h"
+#include "gui.h"
#include "logger.h"
+#include <QApplication>
#include <getopt.h>
#include <iostream>
@@ -36,8 +38,7 @@ static void err()
<< std::endl;
}
-static void
-parseArguments(int argc, char **argv, bool &memory_only)
+static void parseArguments(int argc, char **argv, bool &memory_only)
{
struct option long_options[] = {
{"debug", no_argument, 0, 'd'},
@@ -74,10 +75,14 @@ int main(int argc, char **argv)
if (memory_only) {
Cli cli;
cli.run();
+ } else {
+ global_log->log(INFO, "Starting QT...");
+ QApplication a(argc, argv);
+ Gui w;
+ w.show();
+ a.exec();
}
- // fork off python here
- global_log->log(INFO, "Python started.");
global_log->log(INFO, "Cleaning up...");
global_log->log(INFO, "Goodbye!");
return EXIT_SUCCESS;
diff --git a/gui/resources.qrc b/gui/resources.qrc
new file mode 100644
index 0000000..8bfd4e7
--- /dev/null
+++ b/gui/resources.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC>
+<RCC version="1.0">
+ <qresource prefix="/resources">
+ <file alias="input.txt">resources/input.txt</file>
+ </qresource>
+</RCC>
diff --git a/gui/resources/input.txt b/gui/resources/input.txt
new file mode 100644
index 0000000..fc1c3cf
--- /dev/null
+++ b/gui/resources/input.txt
@@ -0,0 +1 @@
+Lorem Ipsum \ No newline at end of file
diff --git a/inc/cache.h b/inc/cache.h
index ef9c9e4..88fd352 100644
--- a/inc/cache.h
+++ b/inc/cache.h
@@ -4,6 +4,7 @@
#include "storage.h"
#include <array>
#include <ostream>
+#include <functional>
class Cache : public Storage
{
diff --git a/inc/dram.h b/inc/dram.h
index f4d175e..0799015 100644
--- a/inc/dram.h
+++ b/inc/dram.h
@@ -3,6 +3,7 @@
#include "definitions.h"
#include "storage.h"
#include <ostream>
+#include <functional>
class Dram : public Storage
{
diff --git a/inc/logger.h b/inc/logger.h
index 38527c8..88f9e30 100644
--- a/inc/logger.h
+++ b/inc/logger.h
@@ -11,7 +11,7 @@ class Logger
public:
static Logger* getInstance();
- ~Logger();
+ ~Logger() = default;
/**
* Do not allow copies.
@@ -32,15 +32,9 @@ class Logger
void log(LogLevel, const string &);
private:
- /**
- * Constructor.
- * @param The file name to log to.
- * @return A new logger object.
- */
- Logger(const string &);
+ Logger() = default;
static Logger* logger_instance;
static LogLevel level;
- static ofstream logFile;
static string level_to_string(LogLevel);
static int level_to_int(LogLevel);
};
diff --git a/src/gui/gui.py b/src/gui/gui.py
deleted file mode 100644
index e69de29..0000000
--- a/src/gui/gui.py
+++ /dev/null
diff --git a/src/logger/logger.cc b/src/logger/logger.cc
index 55d7a15..6dfaef1 100644
--- a/src/logger/logger.cc
+++ b/src/logger/logger.cc
@@ -6,21 +6,8 @@
using namespace std;
LogLevel Logger::level = INFO;
-ofstream Logger::logFile;
Logger *Logger::logger_instance;
-Logger::Logger(const string &filename)
-{
- if (!filename.empty()) {
- logFile.open(filename, ios::app);
- if (!logFile.is_open()) {
- cerr << "Error opening log file." << endl;
- }
- }
-}
-
-Logger::~Logger() { logFile.close(); }
-
void Logger::setLevel(LogLevel level) { level = level; }
void Logger::log(LogLevel level, const string &message)
@@ -39,17 +26,12 @@ void Logger::log(LogLevel level, const string &message)
<< message << endl;
cout << logEntry.str();
-
- if (logFile.is_open()) {
- logFile << logEntry.str();
- logFile.flush();
- }
}
Logger *Logger::getInstance()
{
if (logger_instance == nullptr) {
- logger_instance = new Logger("vector.log");
+ logger_instance = new Logger();
}
return logger_instance;
}