Skip to content

Commit

Permalink
New DTX Classes
Browse files Browse the repository at this point in the history
New classes for FilesDB: DTXField, DTXChapter, DTXSection and DTXSubSection
  • Loading branch information
CSMathematics committed Oct 10, 2024
1 parent c32e89e commit fbfb980
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 237 deletions.
2 changes: 1 addition & 1 deletion DataTex.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 14.0.1, 2024-10-02T17:10:10. -->
<!-- Written by QtCreator 14.0.1, 2024-10-09T20:02:32. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
48 changes: 10 additions & 38 deletions datatex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,33 +594,7 @@ DataTex::DataTex(QWidget *parent)
}
});

// qDebug()<<dtxSettings.findTexLiveBinFolder();

// QJsonDocument newDatabaseInfo;
// QJsonObject basicObject;
// basicObject["FileName"] = "a_gymnasiou";
// basicObject["IsConnected"] = 1;
// basicObject["Name"] = "Α Γυμνασίου";
// basicObject["Password"];
// basicObject["Path"] = "/home/spyros/Μαθηματικά/Βάσεις Δεδομένων DataTeX/Α Γυμνασίου/a_gymnasiou.db";
// basicObject["Prefix"];
// basicObject["Type"] = 0;
// basicObject["TypeName"] = "Files database";
// basicObject["Username"];

// QStringList array = {"2","3"};
// QJsonArray metaArray;
// for(QString i:array){
// metaArray.append(QJsonValue(i));
// }
// basicObject["Metadata"] = metaArray;
// newDatabaseInfo.setObject(basicObject);

// QFile file("/home/spyros/test.json");
// file.open(QIODevice::WriteOnly);
// file.write(newDatabaseInfo.toJson());
// file.close();

ui->OpenDatabasesGridLayout->addWidget(ui->SideBarViewOptions,0,0);
}

void DataTex::setDefaultAction(QAction* action)
Expand Down Expand Up @@ -663,23 +637,21 @@ void DataTex::CreateMenus_Actions()
AreAllDBConnected();
},"",QIcon::fromTheme("DisconnectDB"),tr("Disconnect selected database"));
ConnectAllDatabase = CreateNewAction(FileMenu,ConnectAllDatabase,[=](){
for(DTXDatabase DTXDB : GlobalDatabaseList.values()){
if(!DTXDB.IsConnected){
QTreeWidgetItem * item = ui->OpenDatabasesTreeWidget->findItems(DTXDB.BaseName,Qt::MatchExactly | Qt::MatchRecursive,2).at(0);
for (auto DTXDB = GlobalDatabaseList.cbegin(), end = GlobalDatabaseList.cend(); DTXDB != end; DTXDB++){
if(!DTXDB->IsConnected){
QTreeWidgetItem * item = ui->OpenDatabasesTreeWidget->findItems(DTXDB->BaseName,Qt::MatchExactly | Qt::MatchRecursive,2).at(0);
SetDatabaseConnected(item);
}
// ConnectAllDatabase->setEnabled(false);
// DisconnectAllDatabase->setEnabled(true);
}
},"",QIcon::fromTheme("ConnectAllDB"),tr("Connect all databases"));
DisconnectAllDatabase = CreateNewAction(FileMenu,DisconnectAllDatabase,[=](){
for(DTXDatabase DTXDB : GlobalDatabaseList.values()){
if(DTXDB.IsConnected){
QTreeWidgetItem * item = ui->OpenDatabasesTreeWidget->findItems(DTXDB.BaseName,Qt::MatchExactly | Qt::MatchRecursive,2).at(0);
for (auto DTXDB = GlobalDatabaseList.cbegin(), end = GlobalDatabaseList.cend(); DTXDB != end; DTXDB++){
if(DTXDB->IsConnected){
QTreeWidgetItem * item = ui->OpenDatabasesTreeWidget->findItems(DTXDB->BaseName,Qt::MatchExactly | Qt::MatchRecursive,2).at(0);
SetDatabaseDisconnected(item);
}
DisconnectAllDatabase->setEnabled(false);
ConnectAllDatabase->setEnabled(true);//If all are unencrypted
ConnectAllDatabase->setEnabled(true);//If all are not encrypted
}
},"",QIcon::fromTheme("DisconnectAllDB"),tr("Disconnect all databases"));
FileMenu->addSeparator();
Expand Down Expand Up @@ -3997,7 +3969,7 @@ void DataTex::SetDatabaseConnected(QTreeWidgetItem * item)
file.open(QFile::ReadWrite | QFile::Text);
QJsonDocument doc(QJsonDocument::fromJson(file.readAll()));
QJsonObject dbObject(doc.object());
dbObject["IsConnected"] = 1;
dbObject["IsConnected"] = true;
file.resize(0);
QJsonDocument newDoc(dbObject);
file.write(newDoc.toJson());
Expand All @@ -4019,7 +3991,7 @@ void DataTex::SetDatabaseDisconnected(QTreeWidgetItem *item)
file.open(QFile::ReadWrite | QFile::Text);
QJsonDocument doc(QJsonDocument::fromJson(file.readAll()));
QJsonObject dbObject(doc.object());
dbObject["IsConnected"] = 0;
dbObject["IsConnected"] = false;
file.resize(0);
QJsonDocument newDoc(dbObject);
file.write(newDoc.toJson());
Expand Down
12 changes: 6 additions & 6 deletions datatex.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1773,8 +1773,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>176</width>
<height>25</height>
<width>185</width>
<height>28</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
Expand Down Expand Up @@ -2215,7 +2215,7 @@
<item>
<widget class="QStackedWidget" name="PreviewStackedWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="MetadataPage">
<layout class="QGridLayout" name="gridLayout_16">
Expand Down Expand Up @@ -2249,8 +2249,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>26</height>
<width>567</width>
<height>611</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
Expand Down Expand Up @@ -3362,8 +3362,8 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="SideBarButtonGroup"/>
<buttongroup name="MenuButtons"/>
<buttongroup name="SideBarButtonGroup"/>
<buttongroup name="ActionButtonGroup"/>
</buttongroups>
</ui>
8 changes: 4 additions & 4 deletions datatex/clonedatabasefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void CloneDatabaseFile::AddFiles(int row)
DTXFile *FileData = new DTXFile;
FileData->Id = Id;
// FileData->FileType<<SqlFunctions::Get_Record_From_Query(QString("SELECT * FROM FileTypes WHERE Name = \'%1\'").arg(FileType),SourceDatabase.Database);
// FileData->Field<<SqlFunctions::Get_Record_From_Query(QString("SELECT * FROM Fields WHERE Name = \'%1\'").arg(Field),SourceDatabase.Database);
// FileData->Field<<SqlFunctions::Get_Record_From_Query(QString("SELECT * FROM Fields WHERE Name = \'%1\'").arg(Field),SourceDatabase.Database);
FileData->Chapters<<FileData->setRecordList(SqlFunctions::GetChapterInfo.arg(Id),SourceDatabase.Database);
FileData->Sections<<FileData->setRecordList(SqlFunctions::GetSectionInfo.arg(Id),SourceDatabase.Database);
FileData->SubSections<<FileData->setRecordList(SqlFunctions::GetSubsectionInfo.arg(Id),SourceDatabase.Database);
Expand Down Expand Up @@ -404,7 +404,7 @@ void CloneDatabaseFile::on_Okbutton_accepted()
if(info->misc.value<int>()==NewFileMode::CloneModeContentAndMetadata){
//Sql queries to clone metadata to destination database
QSqlQuery WriteData(DataTex::CurrentFilesDataBase.Database);
WriteData.exec(QString("INSERT OR IGNORE INTO Fields (Id,Name) VALUES(\"%1\",\"%2\")").arg(info->Field[0],info->Field[1]));
WriteData.exec(QString("INSERT OR IGNORE INTO Fields (Id,Name) VALUES(\"%1\",\"%2\")").arg(info->Field.Id,info->Field.Name));
for (QStringList chapter:info->Chapters) {
WriteData.exec(QString("INSERT OR IGNORE INTO Chapters (Id,Name,Field) VALUES(\"%1\",\"%2\",\"%3\")")
.arg(chapter[0],chapter[1],chapter[2]));
Expand Down Expand Up @@ -556,7 +556,7 @@ void CloneDatabaseFile::on_SelectedFiles_itemClicked(QTreeWidgetItem *item, int
ui->BibliographyBrowser->setText(info->Bibliography);
ui->removeButton->setEnabled(true);
ui->MetadataTable->item(0,0)->setText(info->Id);
ui->MetadataTable->item(1,0)->setText(info->Field[1]);
ui->MetadataTable->item(1,0)->setText(info->Field.Name);
ui->MetadataTable->item(2,0)->setText(chapters.join("|"));
ui->MetadataTable->item(3,0)->setText(sections.join("|"));
ui->MetadataTable->item(4,0)->setText(subsections.join("|"));
Expand All @@ -582,7 +582,7 @@ void CloneDatabaseFile::disableItems(QComboBox * combo,int excludeItems,bool che
bool CloneDatabaseFile::CheckMetadataResemblances(DTXFile * fileInfo, QSqlDatabase destinationDatabase)
{
DTXFile resemblenceInfo;
QStringList check = SqlFunctions::Get_Record_From_Query(QString("SELECT Id='%1',Name='%2' FROM Fields WHERE (Id = '%1' OR Name = '%2')").arg(fileInfo->Field[0],fileInfo->Field[1]),destinationDatabase);
QStringList check = SqlFunctions::Get_Record_From_Query(QString("SELECT Id='%1',Name='%2' FROM Fields WHERE (Id = '%1' OR Name = '%2')").arg(fileInfo->Field.Id,fileInfo->Field.Name),destinationDatabase);

QStringList chapters;
QStringList sections;
Expand Down
2 changes: 1 addition & 1 deletion datatex/clonedatabasefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "style.h"
#include "databasecreator.h"

class DTXFile;
struct DTXFile;
enum NewFileMode {
BasicMode,ImportMode,EditMode,CloneModeOnlyContent,CloneModeContentAndMetadata
};
Expand Down
7 changes: 5 additions & 2 deletions datatex/databasecreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ void DatabaseCreator::on_DatabaseCreator_accepted()
basicObject["Metadata"] = metaArray;
newDatabaseInfo.setObject(basicObject);

QFile file(DataTex::datatexpath+"Databases/"+NewDatabase.BaseName+".json");
QString path = DataTex::datatexpath+"Databases/";
QDir dir(path);
if (!dir.exists())dir.mkpath(path);
QFile file(path+NewDatabase.BaseName+".json");
file.open(QIODevice::WriteOnly);
file.write(newDatabaseInfo.toJson());
file.close();
Expand Down Expand Up @@ -503,7 +506,6 @@ void DatabaseCreator::on_DatabaseCreator_accepted()
newdatabaseFile.close();

emit newbase(NewDatabase);
// QDialog::accept();
}

QString DatabaseCreator::getDatabaseTypeName(int type)
Expand All @@ -528,6 +530,7 @@ QString DatabaseCreator::getDatabaseTypeName(int type)
case DTXDatabaseType::ClassesDB:
return tr("Classes database");
}
// default
}

DTXFileType::DTXFileType(){}
Expand Down
Loading

0 comments on commit fbfb980

Please sign in to comment.