Commit bc840fb5 authored by Denis Khachko's avatar Denis Khachko

Course manager bugfix

parent 3ba868b1
......@@ -112,7 +112,7 @@ QVariant courseModel::data(const QModelIndex &index, int role) const
// qDebug()<<"Draw Mark id"<<index.internalId();
if(nodeM.toElement().attribute("root")=="true")
{
qDebug()<<"Folder";
// qDebug()<<"Folder";
}
return iconByMark(taskMark(index.internalId()),nodeM.toElement().attribute("root")=="true");
//NUZHNO IKONKI ISPOLNITELEY
......@@ -121,7 +121,7 @@ QVariant courseModel::data(const QModelIndex &index, int role) const
{
return QBrush(QColor(255,255,255));
}
qDebug()<<"No" << role<< "role";
// qDebug()<<"No" << role<< "role";
return QVariant();
};
QVariant courseModel::headerData(int section, Qt::Orientation orientation,
......@@ -170,7 +170,7 @@ QVariant courseModel::data(const QModelIndex &index, int role) const
QDomNode courseModel::nodeByRowColumn(int row,int column,QDomNode *parent) const
{
if(!parent)return root;
qDebug()<<"nodeByRowColumn";
// qDebug()<<"nodeByRowColumn";
return parent->childNodes().at(row);
return root;
......@@ -231,7 +231,7 @@ QVariant courseModel::data(const QModelIndex &index, int role) const
bool ok;
int new_id=childs.at(row).toElement().attribute("id","").toInt(&ok);
if(!ok){
qDebug()<<"Bad ID";
// qDebug()<<"Bad ID";
return createIndex(-10,-10,-10);
}
......
......@@ -185,7 +185,7 @@ public:
QDomAttr userPrg=courceXml.createAttribute("prg");
userPrg.setValue(text);
userTextEl.setAttributeNode(userPrg);
qDebug()<<"SET USER PRG"<<index.internalId()<<" test "<<text;
// qDebug()<<"SET USER PRG"<<index.internalId()<<" test "<<text;
}
void setUserText(int id,const QString &text)
{
......@@ -201,7 +201,7 @@ public:
QDomAttr userPrg=courceXml.createAttribute("prg");
userPrg.setValue(text);
userTextEl.setAttributeNode(userPrg);
qDebug()<<"SET USER PRG"<<id << " "<<text;
// qDebug()<<"SET USER PRG"<<id << " "<<text;
}
void setUserTestedText(int id,const QString &text)
{
......@@ -217,7 +217,7 @@ public:
QDomAttr userPrg=courceXml.createAttribute("prg");
userPrg.setValue(text);
userTextEl.setAttributeNode(userPrg);
qDebug()<<"SET TESTED PRG"<<id;
// qDebug()<<"SET TESTED PRG"<<id;
}
QString getUserText(int curTaskId)
......@@ -271,7 +271,7 @@ public:
QDomElement readyEl=node.firstChildElement(tag);
if (readyEl.isNull())
{
qDebug()<<"Create NEW"<<tag;
// qDebug()<<"Create NEW"<<tag;
QDomElement markEl=courceXml.createElement(tag);
node.appendChild(markEl);
readyEl=node.firstChildElement(tag);
......@@ -280,7 +280,7 @@ public:
QDomText text=courceXml.createTextNode(data);
for(int i=0;i<readyEl.childNodes().count();i++)
{
qDebug()<<"SWAP"<<tag;
// qDebug()<<"SWAP"<<tag;
if(readyEl.childNodes().at(i).isText())
{
QDomNode elText=readyEl.childNodes().at(i);
......@@ -337,7 +337,7 @@ public:
return 0;
qDebug()<<"Node is null;";
};
qDebug()<<"MRK:"<<readyEl.text();
// qDebug()<<"MRK:"<<readyEl.text();
return readyEl.text().toInt();
};
......@@ -389,7 +389,7 @@ public:
readyEl.appendChild(text);
}
qDebug()<<"Task "<<id<<" mark"<<taskMark(node)<<" set"<<mark;
// qDebug()<<"Task "<<id<<" mark"<<taskMark(node)<<" set"<<mark;
setParMark(node.parentNode().toElement());
};
......@@ -424,12 +424,12 @@ public:
{
Childs.at(i).toElement().setAttribute("id",first_id+cur_off);
QDomNodeList dep_list=Childs.at(i).toElement().elementsByTagName ("DEPEND");
qDebug()<<"Dep count"<<dep_list.count();
// qDebug()<<"Dep count"<<dep_list.count();
Childs.at(i).toElement().removeChild(Childs.at(i).firstChildElement ("DEPEND"));
for(int j=0;j<dep_list.count();j++)
{
qDebug()<<"dep remove";
// qDebug()<<"dep remove";
};
cur_off=cur_off+setChildsId(Childs.at(i),cur_off+1);
......
......@@ -16,9 +16,13 @@ Plugin::Plugin()
{
courseMenu=new QMenu(trUtf8("Практикум"));
MenuList.append(courseMenu);
rescentMenu=new QMenu(trUtf8("Недавние тетради..."));
// m_actionCourseLoadRescent->setMenu(rescentMenu);
MW=new MainWindowTask();
MW->setup(myResourcesDir(), mySettings());
mainWindow_=MW;
field_no=0;
prevFld=new QAction(trUtf8("Предыдущая обстановка"),this);
nextFld=new QAction(trUtf8("Следующая обстановка"),this);
......@@ -26,13 +30,29 @@ Plugin::Plugin()
connect(prevFld,SIGNAL(triggered()),this,SLOT(prevField()));
nextFld->setEnabled(false);
prevFld->setEnabled(false);
}
}
QList<QMenu*> Plugin::menus()const
{
return MenuList;
};
void Plugin::rebuildRescentMenu()
{
rescentMenu->clear();
qDebug()<<mySettings()->locationDirectory();
QStringList lastFiles= mySettings()->value("Courses/LastFiles","").toString().split(";");
qDebug()<<lastFiles;
if(lastFiles.count()==0)rescentMenu->setEnabled(false);else rescentMenu->setEnabled(true);
for(int i=0;i<lastFiles.count();i++) {
if(lastFiles[i]=="")continue;
QAction *action = rescentMenu->addAction("&"+QString::number(i+1)+" "+lastFiles[i],MW,SLOT(openRescent()));
Q_UNUSED(action);
}
};
QString Plugin::getText()
{
GI * gui = ExtensionSystem::PluginManager::instance()->findPlugin<GI>();
......@@ -318,7 +338,11 @@ QString Plugin::initialize(const QStringList &configurationArguments,
actions=MW->getActions();
for(int i=0;i<actions.count();i++)
{
courseMenu->addAction(actions.at(i));
courseMenu->addAction(actions.at(i));
if(i==0)
{
courseMenu->addMenu(rescentMenu);
}
}
MW->setCS(trUtf8("Кумир"));
MW->setInterface(this);
......@@ -329,6 +353,8 @@ QString Plugin::initialize(const QStringList &configurationArguments,
field_no=0;
courseMenu->addAction(nextFld);
courseMenu->addAction(prevFld);
rebuildRescentMenu();
return error;
}
......@@ -338,6 +364,7 @@ void Plugin::updateSettings(const QStringList & keys)
settingsEditorPage_->setSettingsObject(mySettings());
}
MW->updateSettings(keys, mySettings());
rebuildRescentMenu();
}
......
......@@ -46,6 +46,8 @@ public:
inline QStringList getListOfCourses() const {
return mySettings()->value("Courses/LastFiles","").toString().split(";",QString::SkipEmptyParts);
}
void rebuildRescentMenu();
public slots:
void setEnabled(bool value);
void setTestingResult(ProgramRunStatus status, int value);
......@@ -72,6 +74,7 @@ private /*fields*/:
Widgets::DeclarativeSettingsPage* settingsEditorPage_;
QMenu* courseMenu;
QList<QMenu*> MenuList;
QMenu* rescentMenu;
MainWindowTask* MW;
bool setTextFromFile(QString fname);
void fixOldKumTeacherMark(QDataStream* ds);//Inserts into start program, techer part marker.
......
......@@ -99,8 +99,9 @@ void MainWindowTask::changeEvent(QEvent *e)
}
void MainWindowTask::updateLastFiles(const QString newFile )
{
QStringList lastFiles= settings->value("Courses/LastFiles","").toString().split(";");
QStringList lastFiles= settings->value("Courses/LastFiles","").toString().split(";");
qDebug()<<lastFiles;
qDebug()<<settings->locationDirectory();
if(lastFiles.indexOf(newFile)<0)lastFiles.prepend(newFile);
int max_fid=std::min(lastFiles.count(),10);
QString sett="";
......@@ -108,7 +109,8 @@ void MainWindowTask::updateLastFiles(const QString newFile )
{
sett+= lastFiles.at(i)+";";
}
settings->setValue("Courses/LastFiles",sett);
settings->setValue("Courses/LastFiles",sett);
interface->rebuildRescentMenu();
};
void MainWindowTask::loadCourseData(const QString fileName)
{
......@@ -182,7 +184,7 @@ if(cursFile!=krsFile){//Esli ne udalos po puti - ishem v toyje direktorii
}
QString fileN=fileEl.attribute("fileName");
qDebug()<<"KURS ZAGRUZILI";
//qDebug()<<"KURS ZAGRUZILI";
if(cursFile!=krsFile){
QMessageBox::information( 0, "", trUtf8("Не наеден файл курса:") + fileEl.attribute("fileName"), 0,0,0);
fileN=getFileName(krsFile);
......@@ -192,7 +194,7 @@ if(cursFile!=krsFile){
QFileInfo fi_kurs=QFileInfo(krsFile);
curDir=fi_kurs.absolutePath();
QDomNodeList marksElList=root.elementsByTagName("MARK"); //Оценки
qDebug()<<"Loading marks "<<marksElList.count();
//qDebug()<<"Loading marks "<<marksElList.count();
for(int i=0;i<marksElList.count();i++)
{
int taskId=marksElList.at(i).toElement().attribute("testId").toInt();
......@@ -279,7 +281,7 @@ void MainWindowTask::loadCourse()
// if(!dialog.exec())return;
QString File=QFileDialog::getOpenFileName(this, QString::fromUtf8 ("Открыть файл"), dir, "(*.kurs.xml *.work.xml)");
QString File=QFileDialog::getOpenFileName(this, QString::fromUtf8 ("Открыть файл"), dir, "Xml (*.xml)");
QFileInfo fi(File);
if(!fi.exists())
{
......@@ -337,6 +339,7 @@ void MainWindowTask::loadCourse()
qDebug()<<curDir;
cursWorkFile.setFileName(QDir::currentPath()+"/default.work.xml");
saveCourseFile();
}else
{
......@@ -345,7 +348,21 @@ void MainWindowTask::loadCourse()
};
void MainWindowTask::openRescent()
{
QAction *s = qobject_cast<QAction*>(sender());
QString txt = s->text();
txt.remove(0,1);
QStringList words = txt.split(" ");
if(words.count()<2)return;
QString RobotFile=words[1];
loadCourseFromFile(RobotFile);
// if( LoadFromFile(RobotFile)!=0)QMessageBox::information( mainWidget(), "", QString::fromUtf8("Ошибка открытия файла! ")+RobotFile, 0,0,0);
};
void MainWindowTask::setUpDown(QModelIndex index)
{
......@@ -593,16 +610,18 @@ void MainWindowTask::saveCourse()
{
editRoot->hide();
markProgChange();
QFileDialog dialog(this,trUtf8("Сохранить изменения"),curDir, "(*.work.xml)");
QFileDialog dialog(this,trUtf8("Сохранить изменения"),curDir, "Work files(*.work.xml);;All files (*)");
dialog.setDefaultSuffix("work.xml");
dialog.setAcceptMode(QFileDialog::AcceptSave);
if(!dialog.exec())return;
QFileInfo fi(dialog.selectedFiles().first());
//curDir=fi.absolutePath ();
qDebug()<<"curDir"<<curDir;
QString fileName=dialog.selectedFiles().first();
QString type=fileName.right(9);
if(type!=".work.xml")fileName+=".work.xml";
// QString type=fileName.right(9);
// if(type!=".work.xml")fileName+=".work.xml";
cursWorkFile.setFileName(fileName);
updateLastFiles(fileName);
saveCourseFile();
};
......
......@@ -96,7 +96,7 @@ Q_SIGNALS:
public slots:
void aboutToQuit ();
void openRescent();
void loadCourse();
void loadCourseFromFile(const QString & file);
void returnTested();
......
......@@ -35,6 +35,7 @@ public:
~MainWindowTask();
void setInterface(CSInterface * csInterface){this->csInterface=csInterface;};
void setCS(QString cs){CS=cs;};
KumZadanie task;
void setup();
QString getFileName(QString fileName);
......@@ -106,6 +107,7 @@ private:
CSInterface * csInterface;
QString CS;
bool onTask;
QMenu * practMenu;
courseChanges changes;
QString cursFile;
QList<int> progChange;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment