Example #1
0
void MainWindow::on_actionOpen_Project_triggered()
{
    if(project_open)
        on_actionClose_Project_triggered();

    if(project_open)
        return;

    editor = new DocumentEditorView(this);
    editor->hide();

    QDomDocument doc;
    QString filename = QFileDialog::getOpenFileName(this, QString("Choose Project"), ".", "TRX Project (*.trx)");
    QFile file(filename);
    current_project_directory =  QFileInfo(filename).absoluteDir();
    current_project_name = QFileInfo(filename).baseName();

    qDebug() << "filename: " << filename;

    if (!file.open(QIODevice::ReadOnly | QFile::Text))
        return;

    QString message;

    if (!doc.setContent(&file ,false, &message)) {
        file.close();
        return;
    }

    file.close();

    QDomElement docEl = doc.documentElement();

    QString docName = docEl.toElement().firstChild().nodeValue();
    qDebug() << docEl.toElement().firstChild().nodeValue();

    QDomNode child = docEl.firstChild().nextSibling();
    qDebug() << child.toElement().firstChild().nodeValue();

    qDebug() << QFileInfo(filename).absoluteDir().filePath(child.toElement().firstChild().nodeValue());
    requirements = DocumentView::loadDocument(QFileInfo(filename).absoluteDir().filePath(child.toElement().firstChild().nodeValue()));
    requirements->hide();
    traceability = new TraceabilityView(requirements, this);
    ui->centralWidget->layout()->addWidget(traceability);

    QObject::connect(ui->showReq, SIGNAL(pressed()), this, SLOT(showRequirements()));
    QObject::connect(ui->showEdit, SIGNAL(pressed()), this, SLOT(showEditor()));
    QObject::connect(ui->showTrace, SIGNAL(pressed()), this, SLOT(showTraceability()));
    QObject::connect(editor, SIGNAL(docAdded(DocumentView*)), traceability, SLOT(addModels(DocumentView*)));
    QObject::connect(editor, SIGNAL(removeDocument(int)), traceability, SLOT(removeDocument(int)));

    QHash<DocumentView*, QStandardItemModel*> *traceModelList = traceability->getTraceModelList();
    bool modelset = false;
    child = child.nextSibling();
    while (!child.isNull())
    {
        QDomNode subchild = child.firstChild();
        qDebug() << subchild.toElement().firstChild().nodeValue();
        DocumentView* docview = DocumentView::loadDocument(current_project_directory.dirName() + "/" + subchild.toElement().firstChild().nodeValue());
        subchild = subchild.nextSibling();
        qDebug() << subchild.toElement().firstChild().nodeValue();
        QStandardItemModel *matrix = TraceabilityView::loadMatrix(current_project_directory.dirName() + "/" + subchild.toElement().firstChild().nodeValue()+ "_matrix");

        //traceability->addModels(docview, matrix);
        editor->addLoadedTab(docview);
        matrix->setHorizontalHeaderLabels(docview->getHeader());
        traceModelList->insert(docview, matrix);

        if(!modelset){
            traceability->setMatrixModel(matrix);
            modelset = true;
        }

        child = child.nextSibling();
    }


    traceability->addRowToDocument(requirements, -1);
    traceability->updateReqListModel();
    project_open = true;
    ui->frame_2->hide();
    ui->frame->show();
}