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
2 parents 65b9e4e + fbfb980 commit a9daca0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 51 deletions.
30 changes: 15 additions & 15 deletions datatex/clonedatabasefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ void CloneDatabaseFile::AddFiles(int row)
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->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);
// 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);
FileData->Difficulty = Difficulty.toInt();
FileData->Date = QDateTime::fromString(Date,"dd/M/yyyy hh:mm");
int i = SqlFunctions::Get_String_From_Query(QString("SELECT Solved_Prooved FROM Database_Files WHERE Id = '%1'").arg(Id),SourceDatabase.Database).toInt();
Expand Down Expand Up @@ -405,19 +405,19 @@ void CloneDatabaseFile::on_Okbutton_accepted()
//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.Id,info->Field.Name));
for (QStringList chapter:info->Chapters) {
for (DTXChapter 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]));
.arg(chapter.id,chapter.name,chapter.fieldId));
}
for (QStringList section:info->Sections) {
for (DTXSection section:info->Sections) {
WriteData.exec(QString("INSERT OR IGNORE INTO Sections (Id,Name,Chapter) VALUES(\"%1\",\"%2\",\"%3\")")
.arg(section[0],section[1],section[2]));
.arg(section.id,section.name,section.chapterId));
}
for (QStringList subsection:info->SubSections) {
for (DTXSubSection subsection:info->SubSections) {
WriteData.exec(QString("INSERT OR IGNORE INTO Exercise_Types (Id,Name) VALUES(\"%1\",\"%2\")")
.arg(subsection[0],subsection[1]));
.arg(subsection.id,subsection.name));
WriteData.exec(QString("INSERT OR IGNORE INTO Sections_Exercises (Exercise_Id,Section_Id) VALUES(\"%1\",\"%2\")")
.arg(subsection[0],subsection[2]));
.arg(subsection.id,subsection.sectionId));
}
WriteData.prepare(QString("INSERT OR IGNORE INTO FileTypes (Id,Name,FolderName,Solvable) VALUES(:id,:name,:folder,:sol)"));
WriteData.bindValue(":id",info->FileType.Id);
Expand Down Expand Up @@ -545,9 +545,9 @@ void CloneDatabaseFile::on_SelectedFiles_itemClicked(QTreeWidgetItem *item, int
if(item->parent()/* && !item->parent()->parent()*/){
// ui->CopyData->setEnabled(true);
DTXFile *info = item->data(0,Qt::UserRole).value<DTXFile*>();
QStringList chapters = info->getChaptersNames();
QStringList sections = info->getSectionsNames();
QStringList subsections = info->getSubSectionsNames();
QStringList chapters = info->getNames(info->Chapters);
QStringList sections = info->getNames(info->Sections);
QStringList subsections = info->getNames(info->SubSections);
needsSubSection = 1;//QString(info->FileType.at(3)).toInt();
ui->MetadataTable->resizeRowsToContents();
hasSelection = true;
Expand Down Expand Up @@ -587,8 +587,8 @@ bool CloneDatabaseFile::CheckMetadataResemblances(DTXFile * fileInfo, QSqlDataba
QStringList chapters;
QStringList sections;
QStringList subsections;
for(QStringList chapter:qAsConst(fileInfo->Chapters)){
resemblenceInfo.Chapters.append(SqlFunctions::Get_Record_From_Query(QString("SELECT Id='%1',Name='%2',* FROM Chapters WHERE (Id = '%1' OR Name = '%2')").arg(chapter[0],chapter[1]),destinationDatabase));
for(DTXChapter chapter:qAsConst(fileInfo->Chapters)){
// resemblenceInfo.Chapters.append(SqlFunctions::Get_Record_From_Query(QString("SELECT Id='%1',Name='%2',* FROM Chapters WHERE (Id = '%1' OR Name = '%2')").arg(chapter[0],chapter[1]),destinationDatabase));
}
// = 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]),database);
// = 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]),database);
Expand Down
54 changes: 20 additions & 34 deletions datatex/filecommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,18 @@ void DTXFile::WriteDTexFile()
text += "FileType=("+FileType.getListFromDTXFileType().join(",")+")\n";
text += "Fields=("+Field.Id+","+Field.Name+")\n";
QStringList c;
for (QStringList chapter:Chapters) {
c.append("("+chapter.join(",")+")");
for (DTXChapter chapter:Chapters) {
c.append("("+chapter.id+"<"+chapter.name+"<"+chapter.fieldId+")");
}
text += "Chapters="+c.join("|")+"\n";
QStringList s;
for (QStringList section:Sections) {
s.append("("+section.join(",")+")");
for (DTXSection section:Sections) {
s.append("("+section.id+"<"+section.name+"<"+section.chapterId+")");
}
text += "Sections="+s.join("|")+"\n";
QStringList ss;
for (QStringList subsection:SubSections) {
ss.append("("+subsection.join(",")+")");
for (DTXSubSection subsection:SubSections) {
ss.append("("+subsection.id+"<"+subsection.name+"<"+subsection.sectionId+")");
}
text += "SubSections="+ss.join("|")+"\n";
text += "Difficulty="+QString::number(Difficulty)+"\n";
Expand All @@ -399,20 +399,6 @@ void DTXFile::WriteDTexFile()
newDBFile.close();
}

void DTXFile::setChapters(QString id,QSqlDatabase database)
{
QSqlQuery query(database);
query.exec(SqlFunctions::GetChapterInfo.arg(id));
while(query.next()){
DTXChapter chapter;
chapter.Id = query.record().value(0).toString();
chapter.Name = query.record().value(1).toString();
QString field = query.record().value(0).toString();
Chapters.append(chapter);
}
}


DTXDocument::DTXDocument()
{

Expand Down Expand Up @@ -851,15 +837,15 @@ QList<QHash<QString,QString>> FileCommands::GetFileIdsFromContent(QString Conten

QString FileCommands::NewFilePathAndId(DTXFile *info,bool needsSubSection)
{
QString Chapters = info->getChaptersNames().join("|");
QString Sections = info->getSectionsNames().join("|");
QString ChapterId = info->getChaptersIds().join("");
QString SectionId = info->getSectionsIds().join("");
QString ExTypeId = info->getSubSectionsIds().join("");
QString Chapters = info->getNames(info->Chapters).join(" - ");
QString Sections = info->getNames(info->Sections).join(" - ");
QString ChapterId = info->getIds(info->Chapters).join("");
QString SectionId = info->getIds(info->Sections).join("");
QString SubSectionId = info->getIds(info->SubSections).join("");
QString Path = QFileInfo(DataTex::CurrentFilesDataBase.Path).absolutePath()+QDir::separator()+info->Field.Name+QDir::separator()+Chapters+QDir::separator()+Sections+QDir::separator()+info->FileType.FolderName+QDir::separator();
QString prefix;// = SqlFunctions::Get_String_From_Query(QString("SELECT Prefix FROM DataBases WHERE FileName = '%1'").arg(QFileInfo(DataTex::CurrentFilesDataBase.Path).baseName()),DataTex::DataTeX_Settings);
prefix = (!prefix.isEmpty() && !prefix.isNull()) ? prefix+"-" : QString() ;
QString fileId = (needsSubSection) ? prefix+info->Field.Id+"-"+ChapterId+"-"+SectionId+"-"+ExTypeId+"-"+info->FileType.Id
QString fileId = (needsSubSection) ? prefix+info->Field.Id+"-"+ChapterId+"-"+SectionId+"-"+SubSectionId+"-"+info->FileType.Id
: prefix+info->Field.Id+"-"+ChapterId+"-"+SectionId+"-"+info->FileType.Id;
QStringList ExistingFiles = SqlFunctions::Get_StringList_From_Query(
QString("SELECT Id FROM Database_Files WHERE Id LIKE \"%%1%\"").arg(fileId),DataTex::CurrentFilesDataBase.Database);
Expand Down Expand Up @@ -919,16 +905,16 @@ void FileCommands::AddNewFileToDatabase(DTXFile * fileInfo,QSqlDatabase database
"\",\""+QString::number((int)fileInfo->Solved)+"\",\""+fileInfo->Content+"\",\""+fileInfo->Preamble.Id+
"\",\""+fileInfo->BuildCommand+"\",\""+fileInfo->Description+"\")");
QString fileName = fileInfo->Id;
for(QString Chapter:fileInfo->getChaptersIds()){
writeExercise.exec("INSERT INTO Chapters_per_File (File_Id,Chapter_Id) VALUES (\""+fileName+"\",\""+Chapter+"\")");
qDebug()<<"INSERT INTO Chapters_per_File (File_Id,Chapter_Id) VALUES (\""+fileName+"\",\""+Chapter+"\")";
for(auto chapter = fileInfo->Chapters.cbegin(), end = fileInfo->Chapters.cend() ; chapter != end ; chapter++){
writeExercise.exec("INSERT INTO Chapters_per_File (File_Id,Chapter_Id) VALUES (\""+fileName+"\",\""+chapter->id+"\")");
qDebug()<<"INSERT INTO Chapters_per_File (File_Id,Chapter_Id) VALUES (\""+fileName+"\",\""+chapter->id+"\")";
}
for(QString Section:fileInfo->getSectionsIds()){
writeExercise.exec("INSERT INTO Sections_per_File (File_Id,Section_Id) VALUES (\""+fileName+"\",\""+Section+"\")");
qDebug()<<"INSERT INTO Sections_per_File (File_Id,Section_Id) VALUES (\""+fileName+"\",\""+Section+"\")";
for(auto section = fileInfo->Sections.cbegin(), end = fileInfo->Sections.cend() ; section != end ; section++){
writeExercise.exec("INSERT INTO Sections_per_File (File_Id,Section_Id) VALUES (\""+fileName+"\",\""+section->id+"\")");
qDebug()<<"INSERT INTO Sections_per_File (File_Id,Section_Id) VALUES (\""+fileName+"\",\""+section->id+"\")";
}
for(QString SubSection:fileInfo->getSubSectionsIds()){
writeExercise.exec("INSERT INTO ExerciseTypes_per_File (File_Id,ExerciseType_Id) VALUES (\""+fileName+"\",\""+SubSection+"\")");
for(auto subSection = fileInfo->SubSections.cbegin(), end = fileInfo->SubSections.cend() ; subSection != end ; subSection++){
writeExercise.exec("INSERT INTO ExerciseTypes_per_File (File_Id,ExerciseType_Id) VALUES (\""+fileName+"\",\""+subSection->id+"\")");
}

// Create new tex file and write content
Expand Down
2 changes: 0 additions & 2 deletions datatex/filecommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ struct DTXFile {
}

void WriteDTexFile();

void setChapters(QString id, QSqlDatabase database);
};
//Q_DECLARE_METATYPE(DTXFile)
Q_DECLARE_METATYPE(DTXFile*)
Expand Down

0 comments on commit a9daca0

Please sign in to comment.