Skip to content
Snippets Groups Projects
Commit 4795d24e authored by Dave Casper's avatar Dave Casper
Browse files

Merge branch 'master' into 'master'

Replaced FaserGeoEditor files with latest working version

See merge request faser/calypso!44
parents 101c2c73 94d91bcf
No related branches found
No related tags found
No related merge requests found
# FaserGeoEditorApp
Qt Application for editing and maintaining the Faser GeoModel Sql Database
These are subfiles within larger repository https://gitlab.cern.ch//dcasper/calypso
Requires entire calypso repository to run/compile currently
Replace files found in calypso/DetectorDescription/GeoModel/FaserGeoEditor/src with these files
After following calypso readme to build all files:
cd ../run
source ./setup.sh
FaserGeoEditor data/geomDB_sqlite
The program can currently read a sql file of text commands, or a sql binary file. To differentiate between the file being read, add a third argument to call the program of t for text, b for binary
Note: it cannot read sqlite files currently
ex:
FaserGeoEditor data/geomDB.sql t
Adding rows/columns adds one after the selected index (if none selected inputs new one at beginning)
Changes to table are only saved if submitted
While open the file, along with changes will continuously saved to a binary file GeoEditorSqlite
To finalize the file and resave as a text file, ctrl+s or save in the menu will allow for this
Color coding :
green -associated with an unlocked tag; data can be edited and children tags can be created(if branch)
yellow -associated with a doubly unlocked tag; in general this can lead to unwanted behaviour, and may cause issues if continued. When one of the tags associated is later locked, it will still lock the data but can lead to issues with child tag creations
red -associated with a locked tag. Data cannot be edited and child tags cannot be added. To change data or create children, need to create a new tag at this level that is a copy of the version desired, then create children.
......@@ -7,6 +7,9 @@
#include <QDialog>
#include <QTableView>
#include <QtSql>
#include <QListWidget>
//#include "FaserDbSecondWindow.h"
//#include "FaserDbRelTableModel.h"
// #include <QtGui/QWidget>
......@@ -22,11 +25,14 @@ QT_END_NAMESPACE
class FaserDbSecondWindow;
class FaserDbRelTableModel;
class FaserGeoEditorApp;
class FaserDbMainWindow : public QMainWindow
{
Q_OBJECT
private:
FaserGeoEditorApp *m_editorApp;
QTreeView *m_treeView;
QStandardItemModel *m_standardModel;
QSqlDatabase m_database;
......@@ -37,17 +43,16 @@ private:
QDialogButtonBox *m_buttonBox;*/
FaserDbSecondWindow *m_secondWindow;
QSqlTableModel *m_hvsNodeTableModel;
QMenu *m_viewMenu;
QMenu *m_contextMenu;
QMenu *m_subMenu;
QAction *m_addBranch;
QAction *m_addLeaf;
QAction *m_createTag;
QAction *m_testTag1;
QAction *m_testTag2;
QAction *m_setRoot;
// QAction *m_setRoot;
QAction *m_lockTag;
QString m_currentSelected;
vector<string> m_errors;
QListWidget *m_listWidget;
void printErrors();
void createActions();
......@@ -64,26 +69,36 @@ private:
// string obtainNamePopup();
public:
QSqlTableModel *m_tag2node;
QSqlTableModel *m_tagcache;
QSqlTableModel *m_ltag2ltag;
QString m_rootDisplayTag;
void initializeWindow();
FaserDbMainWindow(QWidget *parent = nullptr);
FaserDbMainWindow(QWidget *parent = nullptr, FaserGeoEditorApp *parentApp = nullptr);
QList<QStandardItem*> prepareRow( const QString& name1, const QString& name2, const QString& name3, const QString& name4, const QString& name5);
void buildChildren( QList<QStandardItem*> *Row, QString parent_id);
void setDatabase( QSqlDatabase *db);
// void submit();
QSqlDatabase returnDatabase();
void rebuildTree();
void saveFile();
void buildListWidget();
bool verifyDatabase();
QString selectedRowName();
void selectionChanged(const QItemSelection&, const QItemSelection&);
void tagRowChanged(int currentRow);
bool isLocked(QString tagId);
QStringList findAssociatedList(QSqlTableModel *table, QString known, QString kvalue, QString search);
QString findAssociated(QSqlTableModel *table, QString known, QString kvalue, QString search);
QString createTag();
QString createRootTag();
void lockTag(QString toLock = QString());
void errorMessage(string message);
bool submitChanges(QSqlTableModel *table);
// virtual ~FaserDbMainWindow();
......@@ -99,11 +114,14 @@ public:
FaserDbPopup(FaserDbMainWindow *window_parent, QWidget *parent = nullptr);
};*/
class FaserDbSecondWindow : public QWidget
{
Q_OBJECT
private:
QSqlRelationalTableModel *m_tableModel;
// QSqlRelationalTableModel *m_tableModel;
FaserDbRelTableModel *m_tableModel;
// QSqlTableModel *m_tableModel; previously used, replaced with relational
QPushButton *m_submitButton;
QPushButton *m_revertButton;
......@@ -113,14 +131,17 @@ private:
QPushButton *m_removeColumn;
QPushButton *m_removeRow;
QDialogButtonBox *m_buttonBox;
FaserDbMainWindow *m_parentWindow;
QTableView *m_tableView;
QString m_rootTag;
public:
QTableView *m_tableView;
QSqlTableModel *m_tagTable;
QSqlTableModel *m_sqlTableModel;
FaserDbMainWindow *m_parentWindow;
FaserDbSecondWindow( FaserDbMainWindow *window_parent, QWidget *parent = nullptr);
~FaserDbSecondWindow();
void submit();
// QSqlTableModel* tablePointer();
void addRow();
......@@ -132,18 +153,24 @@ public:
void setTagFilter(QString tagFilter);
void click_cell(int row, int column);
vector<bool> m_isLocked;
// Qt::ItemFlags flags(const QModelIndex &index) const;
};
class testtest : public QSqlRelationalTableModel
{
class FaserDbRelTableModel : public QSqlRelationalTableModel
{
private:
FaserDbSecondWindow *m_secondWindow;
public:
FaserDbRelTableModel(QObject *parent, QSqlDatabase db, FaserDbSecondWindow *secondWin);
QVariant data(const QModelIndex &idx, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
};
//Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex &index) const;
// #endif
\ No newline at end of file
#include <iostream>
#include <QFile>
#include "FaserGeoEditorApp.h"
FaserGeoEditorApp::FaserGeoEditorApp(int& argc, char** argv)
: m_application(argc, argv), m_database(QSqlDatabase::addDatabase("QSQLITE")), m_mainWindow()
FaserGeoEditorApp::FaserGeoEditorApp(int& argc, char** argv, string type)
: m_application(argc, argv), m_database(QSqlDatabase::addDatabase("QSQLITE")), m_mainWindow(nullptr, this)
{
//Need to separate cases of opening a text and binary file
/* if(type = "t")
{
//do something here
}
else
{
m_application = new QApplication(argc, argv);
m_database = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE"));
m_mainWindow = new FaserDbMainWindow(nullptr, this);
}*/
// db file name should be first argument after command name; retrieve it
auto arguments = m_application.arguments();
auto dbName = arguments.at(1);
std::cout << "Database name: " << dbName.toLocal8Bit().constData() << std::endl;
m_database.setDatabaseName(dbName);
bool ok = m_database.open();
bool ok;
cout<<"type:"<<type<<endl;
if( strcmp(type.c_str(), "b") == 0)
{
m_database.setDatabaseName(dbName);
ok = m_database.open();
}
else
{
cout<<"Binary file will initially be saved to current directory as GeoEditorSqlite\n";
m_database.setDatabaseName("GeoEditorSqlite");
ok = m_database.open();
if(ExecuteSqlScriptFile( m_database, dbName) == 0)
{
cout<<"Exiting...\n";
return;
}
}
std::cout << "Database open status: " << ok << std::endl;
if(!ok)
{
cout<<"Failed to open database, exiting...\n";
return;
}
m_mainWindow.setDatabase(&m_database);
m_mainWindow.initializeWindow();
......@@ -23,4 +60,33 @@ int FaserGeoEditorApp::exec()
{
m_mainWindow.show();
return m_application.exec();
}
\ No newline at end of file
}
int FaserGeoEditorApp::ExecuteSqlScriptFile(QSqlDatabase & db, const QString & fileName)
{
cout<<"executing\n";
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
cout<<"Error opening file to save to\n";
return 0;
}
QTextStream in(&file);
QString sql = in.readAll();
QStringList sqlStatements = sql.split(';', QString::SkipEmptyParts);
int successCount = 0;
foreach(const QString& statement, sqlStatements)
{
if (statement.trimmed() != "")
{
QSqlQuery query(db);
if (query.exec(statement))
successCount++;
else
std::cout << "Failed:" << statement.toStdString() << "\nReason:" << query.lastError().text().toStdString()<<endl;
}
}
return successCount;
}
......@@ -9,9 +9,13 @@
class FaserGeoEditorApp
{
public:
FaserGeoEditorApp(int& argc, char** argv);
FaserGeoEditorApp(int& argc, char** argv, string type);
// string textToBinary(string fileName);
// string binaryToText(string fileName);
int exec();
int ExecuteSqlScriptFile(QSqlDatabase & db, const QString & fileName);
QSqlDatabase& getDatabase() { return m_database; }
private:
QApplication m_application;
......
// main.cpp
#include "FaserGeoEditorApp.h"
#include <iostream>
// #include <QTableView>
// #include <QStringList>
// #include <QSqlDatabase>
// #include <iostream>
// #include "mymodel.h"
//#include <string.h>
//#include <sqlite3.h>
//#include <fstream>
//string textToBinary(string textFileName, string binFileName = std::string(""));
int main(int argc, char *argv[])
{
FaserGeoEditorApp a(argc, argv);
if(argc != 3)
{
std::cout<<"Error: Require two command line inputs only, first path to application, second path to database, third to indicate binary vs text file\n";
std::cout<<"Example: bin/FaserGeoEditor data/geomDB_sqlite t\n";
return 0;
}
string type;
string fileName;
if( strcmp(argv[2], "t") || strcmp(argv[2], "T"))
{
type = "t";
// fileName = textToBinary(argv[1]);
}
else if( strcmp(argv[2], "b") || strcmp(argv[2], "B"))
{
type = "b";
}
else
{
std::cout<<argv[2]<<endl;
std::cout<<"Error: third argument incorrectly indicating if file is text or binary; only use t or b to indicate\n";
return 0;
}
char *reducedArgv[2];
reducedArgv[0] = argv[0];
reducedArgv[1] = argv[1];
argc = 2;
FaserGeoEditorApp a(argc, reducedArgv, type);
// QApplication a(argc, argv);
// QTableView tableView;
......@@ -19,3 +53,54 @@ int main(int argc, char *argv[])
// w.show();
return a.exec();
}
/*
string textToBinary(string textFileName, string binFileName)
{
int rc;
char *zErrMsg;
sqlite3 *database;
string sqlFileName = textFileName;
sqlFileName.append("sql");
string sqlToRun;
string singlestring;
rc = sqlite3_open((sqlFileName).c_str(), &database);
if(rc)
{
cout<<"Failed to open file\n\n";
return nullptr;
}
else
{
cout<<"File opened\n\n";
}
cout<<"Enter name of sql file:";
cin>>textFileName;
ifstream openedFile;
openedFile.open(textFileName.c_str());
while(!openedFile.eof())
{
sqlToRun.clear();
singlestring = "a";
while(!openedFile.eof() && *singlestring.rbegin() != ';')
{
singlestring.clear();
getline(openedFile, singlestring);
sqlToRun = sqlToRun + singlestring;
}
rc = sqlite3_exec(database, sqlToRun.c_str(), NULL, 0, &zErrMsg);
if( rc!=SQLITE_OK)
{
cout<<zErrMsg;
cout<<"\n";
sqlite3_free(zErrMsg);
}
}
cout<<"SQL commands run successfully!\n\n";
return sqlFileName;
}*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment