Commit ff55344e authored by Denis Khachko's avatar Denis Khachko

Course Manager

parent 25e5f634
......@@ -7,10 +7,14 @@ include(../../kumir2_plugin.cmake)
set(SOURCES
coursemanager_plugin.cpp
task/mainwindow.cpp
)
set(MOC_HEADERS
coursemanager_plugin.h
task/mainwindow.h
)
qt4_wrap_cpp(MOC_SOURCES ${MOC_HEADERS})
......
#include "course_model.h"
#include <QSize>
#include <QColor>
#include <QBrush>
#include <QIcon>
#define MARK_BLOCK 12
int courseModel::loadCourse(QString file)
{
courseFileName=file;
qDebug()<<"Load Course";
QFile f(courseFileName);
if (!f.open(QIODevice::ReadWrite))
{
qDebug()<<"cant open"<<courseFileName;
return -1;
};
if(f.atEnd())return -1;
QString error;
courceXml.setContent(f.readAll(),true,&error);
f.close();
qDebug()<<"File parce:"<<error;
int count=0;
taskCount=count;
root=courceXml.documentElement();
insertRow(0);
insertColumn(0);
setData(createIndex(0,0),QVariant());
buildCash();
return count;
}
int courseModel::rowCount(const QModelIndex &parent) const
{
// qDebug()<<"RowCount"<< parent;
if(!parent.isValid())
{
// qDebug()<<"NOT VALID"<<" count"<<root.childNodes().length();
return 1;
};
QDomNode node=nodeById(parent.internalId(),root);
return subTasks(node);
}
QIcon courseModel::iconByMark(int mark,bool isFolder)const
{
if(isFolder)mark=mark+MARK_BLOCK;
// qDebug()<<"Mark:"<<mark;
if((mark>-1)&&(mark<2*MARK_BLOCK))return markIcons[mark];
return QIcon(":/x.png");
}
QVariant courseModel::data(const QModelIndex &index, int role) const
{
//qDebug()<<"Get data"<<index<<" role"<<role;
if (!index.isValid())
return QVariant();
QDomNode node=nodeById(index.internalId(),root);
if(role==Qt::DisplayRole)
{
QString title=node.toElement().attribute("name","");
return QVariant(title);
};
if(role==Qt::SizeHintRole)
{
QDomNode nodeM=nodeById(index.internalId(),root);
if(nodeM.toElement().attribute("root")=="true")
{
return QVariant(QSize(30,30));
}
return QVariant(QSize(30,30));
}
if(role==Qt::FontRole)
{
return QVariant();
}
if(role==Qt::TextAlignmentRole)
{
return QVariant(Qt::AlignLeft |Qt::AlignVCenter );
}
if(role==Qt::ForegroundRole)
{
if(isTeacher)QVariant(QBrush(QColor(0,0,0)));
if(!taskAvailable(node))
return QVariant(QBrush(QColor(150,150,150)));
return QVariant(QBrush(QColor(0,0,0)));
}
if(role==Qt::CheckStateRole)
{
return QVariant();
}
if(role==Qt::DecorationRole)
{
QDomNode nodeM=nodeById(index.internalId(),root);
// qDebug()<<"Draw Mark id"<<index.internalId();
if(nodeM.toElement().attribute("root")=="true")
{
qDebug()<<"Folder";
}
return iconByMark(taskMark(index.internalId()),nodeM.toElement().attribute("root")=="true");
//NUZHNO IKONKI ISPOLNITELEY
}
if(role==Qt::BackgroundRole)
{
return QBrush(QColor(255,255,255));
}
qDebug()<<"No" << role<< "role";
return QVariant();
};
QVariant courseModel::headerData(int section, Qt::Orientation orientation,
int role ) const
{//qDebug()<<"Get Header";
return QVariant(courseFileName);};
QModelIndex courseModel::index(int row, int column, const QModelIndex &parent) const{
// qDebug()<<"index"<<" ROW:"<<row<<" column:"<<column;
if (!hasIndex(row, column, parent))
return QModelIndex();
// qDebug()<<root.attribute("id","");
return createMyIndex(row,column,parent);
};
int courseModel::domRow(QDomNode &child)const //TODO Check
{
QDomNode par=child.parentNode();
QDomNodeList list=par.childNodes();
for(int i=0;i<list.count();i++)
{
if(child==list.at(i))return i;
}
return 0;
};
QModelIndex courseModel::parent(const QModelIndex &child) const
{
if (!child.isValid())
return QModelIndex();
if(child.internalId()==0)return QModelIndex();
QDomNode child_n=nodeById(child.internalId(),root);
// if(child_n.isNull())return QModelIndex();
QDomNode par=child_n.parentNode();
if(par.toElement().attribute("id").toInt()==0) return createIndex(0,0,0);
return createIndex(domRow(par),0,idByNode(par));
};
int courseModel::columnCount(const QModelIndex &parent)const
{
return 1;} ;
QDomNode courseModel::nodeByRowColumn(int row,int column,QDomNode *parent) const
{
if(!parent)return root;
qDebug()<<"nodeByRowColumn";
return parent->childNodes().at(row);
return root;
};
QDomNode courseModel::nodeById( int id,QDomNode parent) const
{
if(parent.toElement().attribute("id","")==QString::number(id))return parent;
if(!parent.hasChildNodes())return QDomNode();
QDomNode val=cash.value(id);
if(!val.isNull())return val;
QDomNodeList childs=parent.childNodes();
for(int i=0;i<childs.length();i++)
{
if(childs.at(i).toElement().attribute("id","")==QString::number(id))
{
// if(cash.contains(id)<1)
//cash.insert(id,childs.at(i));
return childs.at(i);
};
}
for(int i=0;i<childs.length();i++)
{
// if(childs.at(i).toElement().attribute("id","")==QString::number(id))return childs.at(i);
if(childs.at(i).hasChildNodes())
{
QDomNode toret=nodeById(id,childs.at(i));
if(!toret.isNull())return toret;
}
}
return QDomNode();
};
Qt::ItemFlags courseModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
// qDebug()<<"IS teacher:"<<isTeacher;
if(isTeacher)return Qt::ItemIsEnabled |Qt::ItemIsSelectable|Qt::ItemIsDragEnabled;
if(!taskAvailable(index.internalId()))return Qt::NoItemFlags;
// qDebug()<<"Flags:"<<index.internalId();
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QModelIndex courseModel::createMyIndex(int row,int column,QModelIndex parent) const
{
if(!parent.isValid())return createIndex(0,0,0);
int id=parent.internalId();
if(id<0)return QModelIndex();
QDomNode par=nodeById(id,root);
if(par.isNull())return QModelIndex();
QDomNodeList childs=par.childNodes();
if(childs.count()<=row)return QModelIndex();
bool ok;
int new_id=childs.at(row).toElement().attribute("id","").toInt(&ok);
if(!ok){
qDebug()<<"Bad ID";
return createIndex(-10,-10,-10);
}
return createIndex(row,column,new_id);
};
QString courseModel::getTaskText(QModelIndex index)
{
if(!index.isValid())return "INDEX NOT VALID";
QDomNode node=nodeById(index.internalId(),root);
QDomElement titleEl=node.firstChildElement("DESC");
if(titleEl.isNull())return "";
return titleEl.text();
};
QString courseModel::getTaskCheck(QModelIndex index)
{
if(!index.isValid())return "INDEX NOT VALID";
QDomNode node=nodeById(index.internalId(),root);
QDomElement titleEl=node.firstChildElement("CHECK");
if(titleEl.isNull())return "";
return titleEl.text();
};
QString courseModel::csName(int index)
{
QDomNode node=nodeById(index,root);
QDomElement csEl=node.firstChildElement("CS");
if(csEl.isNull())return "NO CS";
return csEl.text();
};
QString courseModel::progFile(int index)
{
QDomNode node=nodeById(index,root);
QDomElement csEl=node.firstChildElement("PROGRAM");
if(csEl.isNull())return "";
return csEl.text();
};
QStringList courseModel::Modules(int index)
{
QDomNode node=nodeById(index,root);
QDomElement csEl=node.firstChildElement("ISP");
// qDebug()<<"csEl isNull:"<<csEl.isNull();
QStringList modules;
while(!csEl.isNull())
{
modules<<csEl.attribute("ispname");
csEl=csEl.nextSiblingElement("ISP");
};
return modules;
};
void courseModel::setIsps(QModelIndex index,QStringList isp)
{
QDomNode node=nodeById(index.internalId(),root);
QDomElement csEl=node.firstChildElement("ISP");
while (!csEl.isNull ())
{
node.removeChild ( csEl );
csEl=node.firstChildElement("ISP");
};
for(int i=0;i<isp.count();i++)
{
if(isp.at(i)=="")continue;
QDomText text=courceXml.createTextNode(isp.at(i));
qDebug()<<"Append ISP"<<isp.at(i);
QDomElement ispEl=courceXml.createElement("ISP");
ispEl.setAttribute("xml:ispname",isp.at(i));
node.toElement().appendChild(ispEl);
}
};
void courseModel::setIspEnvs(QModelIndex index,QString isp,QStringList Envs)
{
QDomNode node=nodeById(index.internalId(),root);
QDomElement csEl=node.firstChildElement("ISP");
while(!csEl.isNull())
{
// qDebug()<<"ISP NAME"<<csEl.attribute("ispname")<<" isp:"<<isp;
//modules<<csEl.attribute(ispName);
if(csEl.attribute("ispname")==isp)
{
QDomNodeList childList=csEl.childNodes();
for(int j=0;j<childList.count();j++)
{
if(childList.at(j).nodeName()=="ENV")csEl.removeChild(childList.at(j));
}
for(int i=0;i<Envs.count();i++)
{
QDomText text=courceXml.createTextNode(Envs.at(i));
qDebug()<<"Append Env"<<Envs.at(i);
QDomElement envEl=courceXml.createElement("ENV");
csEl.toElement().appendChild(envEl);
envEl.appendChild(text);
}
}
csEl=csEl.nextSiblingElement("ISP");
};
};
QStringList courseModel::Fields(int index,QString isp)
{
QDomNode node=nodeById(index,root);
QDomElement csEl=node.firstChildElement("ISP");
QStringList fields;
while(!csEl.isNull())
{
// qDebug()<<"ISP NAME"<<csEl.attribute("ispname")<<" isp:"<<isp;
//modules<<csEl.attribute(ispName);
if(csEl.attribute("ispname")==isp)
{
QDomElement fieldEl=csEl.firstChildElement("ENV");
while(!fieldEl.isNull())
{
//qDebug()<<"fiield:"<<fieldEl.text();
fields.append(fieldEl.text());
fieldEl=fieldEl.nextSiblingElement("ENV");
}
// qDebug()<<"Return fiield:"<<fields;
return fields;
}
csEl=csEl.nextSiblingElement("ISP");
};
return fields;
};
QString courseModel::Script(int index,QString isp)
{
QDomNode node=nodeById(index,root);
QDomElement csEl=node.firstChildElement("ISP");
while(!csEl.isNull())
{
if(csEl.attribute("ispname","")==isp)
{
QDomElement fieldEl=csEl.firstChildElement("CONTROL");
qDebug()<<"Script name from XML:"<<fieldEl.text();
return fieldEl.text();
}
csEl=csEl.nextSiblingElement("ISP");
};
return "";
};
This diff is collapsed.
#include "coursemanager_plugin.h"
namespace CourseManager {
Plugin::Plugin()
: ExtensionSystem::KPlugin()
, mainWindow_(nullptr)
......@@ -10,6 +13,8 @@ Plugin::Plugin()
{
courseMenu=new QMenu(trUtf8("Практикум"));
MenuList.append(courseMenu);
MW=new MainWindowTask();
mainWindow_=MW;
}
QList<QMenu*> Plugin::Menus()const
{
......
......@@ -6,8 +6,13 @@
#include <extensionsystem/kplugin.h>
#include <interfaces/coursesinterface.h>
#include <extensionsystem/declarativesettingspage.h>
#include "extensionsystem/pluginmanager.h"
#include "shared/guiinterface.h"
typedef Shared::GuiInterface GI;
//#include "task/mainwindow.h"
class MainWindowTask;
namespace CourseManager {
class Plugin
: public ExtensionSystem::KPlugin
......@@ -41,6 +46,7 @@ private /*fields*/:
ExtensionSystem::DeclarativeSettingsPage* settingsEditorPage_;
QMenu* courseMenu;
QList<QMenu*> MenuList;
MainWindowTask* MW;
};
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 13.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="10.071px" height="15.251px" viewBox="0 0 10.071 15.251" enable-background="new 0 0 10.071 15.251" xml:space="preserve">
<g>
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="3.2788" y1="0" x2="3.2788" y2="15.061">
<stop offset="0" style="stop-color:#FF0000"/>
<stop offset="0.0365" style="stop-color:#FD2604"/>
<stop offset="0.0851" style="stop-color:#FB5009"/>
<stop offset="0.1344" style="stop-color:#F9740D"/>
<stop offset="0.1839" style="stop-color:#F79010"/>
<stop offset="0.2336" style="stop-color:#F6A312"/>
<stop offset="0.2838" style="stop-color:#F5AF14"/>
<stop offset="0.3352" style="stop-color:#F5B314"/>
<stop offset="0.5206" style="stop-color:#F8850F"/>
<stop offset="0.94" style="stop-color:#FE1102"/>
<stop offset="1" style="stop-color:#FF0000"/>
</linearGradient>
<path fill="url(#SVGID_1_)" d="M6.027,12.773c0.232,0.263,0.391,0.538,0.477,0.823c0.084,0.287,0.069,0.557-0.047,0.812
c-0.115,0.256-0.367,0.414-0.754,0.476c-0.742,0.124-1.508,0.182-2.297,0.175c-0.789-0.009-1.532-0.02-2.228-0.035
c-0.48,0-0.809-0.147-0.986-0.441C0.014,14.29-0.04,13.968,0.029,13.62c0.07-0.348,0.259-0.664,0.569-0.951
c0.309-0.286,0.704-0.43,1.183-0.43V3.793C1.58,3.84,1.379,3.828,1.178,3.758C0.977,3.688,0.799,3.584,0.645,3.445
C0.49,3.306,0.37,3.14,0.285,2.946S0.172,2.556,0.204,2.354c0.046-0.34,0.22-0.688,0.522-1.044c0.302-0.356,0.653-0.65,1.056-0.882
c0.402-0.232,0.816-0.372,1.242-0.418c0.425-0.047,0.792,0.062,1.102,0.325C4.249,0.429,4.36,0.56,4.462,0.73
c0.101,0.17,0.15,0.324,0.15,0.464c0.015,1.856,0.019,3.701,0.012,5.534c-0.008,1.833-0.012,3.671-0.012,5.511h0.604
C5.525,12.333,5.796,12.511,6.027,12.773z"/>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 13.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Layer_2"
x="0px"
y="0px"
width="16"
height="16"
viewBox="0 0 26.375174 16"
enable-background="new 0 0 17.795 15.161"
xml:space="preserve"
inkscape:version="0.48.2 r9819"
sodipodi:docname="10.svg"><metadata
id="metadata3101"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs3099" /><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1281"
inkscape:window-height="839"
id="namedview3097"
showgrid="false"
inkscape:zoom="21.7"
inkscape:cx="14.740852"
inkscape:cy="15"
inkscape:window-x="60"
inkscape:window-y="23"
inkscape:window-maximized="0"
inkscape:current-layer="Layer_2" />
<linearGradient
id="SVGID_1_"
gradientUnits="userSpaceOnUse"
x1="8.8970003"
y1="0"
x2="8.8970003"
y2="15.1611"
gradientTransform="matrix(1.0725759,0,0,1.2605999,3.8395288,-1.3168996)">
<stop
offset="0"
style="stop-color:#FF0000"
id="stop3073" />
<stop
offset="0.0365"
style="stop-color:#FD2604"
id="stop3075" />
<stop
offset="0.0851"
style="stop-color:#FB5009"
id="stop3077" />
<stop
offset="0.1344"
style="stop-color:#F9740D"
id="stop3079" />
<stop
offset="0.1839"
style="stop-color:#F79010"
id="stop3081" />
<stop
offset="0.2336"
style="stop-color:#F6A312"
id="stop3083" />
<stop
offset="0.2838"
style="stop-color:#F5AF14"
id="stop3085" />