Example #1
0
MainWindow::MainWindow()
{
    // User interface ----------------------------------------------------------
    if (tr("LTR") == "RTL") {
        qApp->setLayoutDirection(Qt::RightToLeft);
    }
    setupUi(this);
    network_access_manager = new QNetworkAccessManager(this);
    default_printer = NULL;
#ifdef Q_OS_MAC
    this->setUnifiedTitleAndToolBarOnMac(true);
#endif
    progressBar = new QProgressBar(this);
    progressBar->setTextVisible(false);
    progressBar->resize(QSize(30, 10));
    statusBar()->addPermanentWidget(progressBar, 0);
    statusBar()->setFixedHeight(20);
    progressBar->setFixedWidth(150);
    progressBar->setFixedHeight(15);
    progressBar->setVisible(false);
    LQCategoryComboBox->setVisible(false);
    SQStatisticsLabel->setVisible(false);
    currentSvgChanged();
    btnApply = SQButtonBox->button(QDialogButtonBox::Apply);
    btnApply->setText(tr("Apply"));
    btnApply->setStatusTip(tr("Apply any changes you have made to the question"));
    btnApply->setIcon(QIcon(QString::fromUtf8(":/images/images/button_ok.png")));
    btnDiscard = SQButtonBox->button(QDialogButtonBox::Discard);
    btnDiscard->setText(tr("Discard"));
    btnDiscard->setStatusTip(tr("Discard any changes you have made to the question"));
    btnDiscard->setIcon(QIcon(QString::fromUtf8(":/images/images/button_cancel.png")));
    SQQuestionTextEdit->setTitle(tr("Question:"));
    SQQuestionTextEdit->textEdit()->setStatusTip(tr("Text of the selected question"));
    ECTextEdit->setTitle(tr("Comments:"));
    ECTextEdit->textEdit()->setStatusTip(tr("Use this field for your comments, notes, reminders..."));
    EFTreeWidget->setMouseTracking(true);
    EFTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Fixed);
    EFTreeWidget->header()->setSectionResizeMode(1, QHeaderView::Stretch);
    EFTreeWidget->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
    EFButtonBox->button(QDialogButtonBox::Apply)->setText(tr("Apply"));
    EFButtonBox->button(QDialogButtonBox::Apply)->setStatusTip(tr("Apply any changes you have made to the categories"));
    EFButtonBox->button(QDialogButtonBox::Apply)->setIcon(QIcon(QString::fromUtf8(":/images/images/button_ok.png")));
    EFButtonBox->button(QDialogButtonBox::Discard)->setText(tr("Discard"));
    EFButtonBox->button(QDialogButtonBox::Discard)->setStatusTip(tr("Discard any changes you have made to the categories"));
    EFButtonBox->button(QDialogButtonBox::Discard)->setIcon(QIcon(QString::fromUtf8(":/images/images/button_cancel.png")));
    // Initialize variables ----------------------------------------------------
    // URLs
    docs_url = tr("http://itest.sourceforge.net/documentation/%1/en/").arg("1.4");
    // i18n
    QTranslator translator; translator.load(":/i18n/iTest-i18n.qm");
    itest_i18n.insert("English", "en");
    itest_i18n.insert(translator.translate("LanguageNames", "Slovak"), "sk");
    itest_i18n.insert(translator.translate("LanguageNames", "Russian"), "ru");
    itest_i18n.insert(translator.translate("LanguageNames", "Turkish"), "tr");
    itest_i18n.insert(translator.translate("LanguageNames", "Portuguese"), "pt");
    itest_i18n.insert(translator.translate("LanguageNames", "Spanish"), "es");
    itest_i18n.insert(translator.translate("LanguageNames", "Italian"), "it");
    itest_i18n.insert(translator.translate("LanguageNames", "Latvian"), "lv");
    itest_i18n.insert(translator.translate("LanguageNames", "Ukrainian"), "uk");
    itest_i18n.insert(translator.translate("LanguageNames", "Czech"), "cs");
    itest_i18n.insert(translator.translate("LanguageNames", "Hungarian"), "hu");
    itest_i18n.insert(translator.translate("LanguageNames", "German"), "de");
    // CURRENT_DB
    current_db_open = false;
    current_db_session = NULL;
    current_db_class = NULL;
    current_db_categories.resize(20);
    current_db_categories_enabled.resize(20);
    // Connect slots -----------------------------------------------------------
    tbtnAddQuestion->setDefaultAction(actionAdd);
    tbtnDuplicateQuestion->setDefaultAction(actionDuplicate);
    tbtnDeleteQuestion->setDefaultAction(actionDelete);
    QObject::connect(actionAdd, SIGNAL(triggered()), this, SLOT(addQuestion()));
    QObject::connect(actionDelete, SIGNAL(triggered()), this, SLOT(deleteQuestion()));
    QObject::connect(actionDuplicate, SIGNAL(triggered()), this, SLOT(duplicateQuestion()));
    QObject::connect(btnApply, SIGNAL(released()), this, SLOT(applyQuestionChanges()));
    QObject::connect(actionApply, SIGNAL(triggered()), this, SLOT(applyQuestionChanges()));
    QObject::connect(btnDiscard, SIGNAL(released()), this, SLOT(discardQuestionChanges()));
    QObject::connect(actionDiscard, SIGNAL(triggered()), this, SLOT(discardQuestionChanges()));

    QObject::connect(actionNew, SIGNAL(triggered()), this, SLOT(newDB()));
    QObject::connect(btnNew, SIGNAL(released()), this, SLOT(newDB()));
    QObject::connect(actionOpen, SIGNAL(triggered()), this, SLOT(open()));
    QObject::connect(btnOpenOther, SIGNAL(released()), this, SLOT(open()));
    QObject::connect(btnOpenSelected, SIGNAL(released()), this, SLOT(openRecent()));
    QObject::connect(actionSave, SIGNAL(triggered()), this, SLOT(save()));
    QObject::connect(actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
    QObject::connect(actionSave_a_copy, SIGNAL(triggered()), this, SLOT(saveCopy()));
    QObject::connect(actionExport_CSV, SIGNAL(triggered()), this, SLOT(exportCSV()));
    QObject::connect(actionClose, SIGNAL(triggered()), this, SLOT(closeDB()));
    QObject::connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
    QObject::connect(actionAbout, SIGNAL(triggered()), this, SLOT(about()));

    QObject::connect(recentDBsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(openRecent(QListWidgetItem *)));
    QObject::connect(LQListWidget, SIGNAL(currentTextChanged(QString)), this, SLOT(setCurrentQuestion()));

    QObject::connect(actionFrom_A_to_Z, SIGNAL(triggered()), this, SLOT(sortQuestionsAscending()));
    QObject::connect(actionFrom_Z_to_A, SIGNAL(triggered()), this, SLOT(sortQuestionsDescending()));
    QObject::connect(actionBy_category, SIGNAL(triggered()), this, SLOT(sortQuestionsByCategory()));

    tbtnAddSVG->setDefaultAction(actionAdd_SVG);
    tbtnRemoveSVG->setDefaultAction(actionRemove_SVG);
    tbtnEditSVG->setDefaultAction(actionEdit_SVG);
    tbtnExportSVG->setDefaultAction(actionExport_SVG);
    QObject::connect(actionAdd_SVG, SIGNAL(triggered()), this, SLOT(addSvg()));
    QObject::connect(actionRemove_SVG, SIGNAL(triggered()), this, SLOT(removeSvg()));
    QObject::connect(actionEdit_SVG, SIGNAL(triggered()), this, SLOT(editSvg()));
    QObject::connect(actionExport_SVG, SIGNAL(triggered()), this, SLOT(exportSvg()));
    QObject::connect(SQSVGListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(previewSvg(QListWidgetItem *)));
    QObject::connect(SQSVGListWidget, SIGNAL(currentTextChanged(QString)), this, SLOT(currentSvgChanged()));

    tbtnMoveUp->setDefaultAction(actionMove_up);
    tbtnMoveDown->setDefaultAction(actionMove_down);
    QObject::connect(actionMove_up, SIGNAL(triggered()), this, SLOT(moveUp()));
    QObject::connect(actionMove_down, SIGNAL(triggered()), this, SLOT(moveDown()));
    QObject::connect(actionMove_to_top, SIGNAL(triggered()), this, SLOT(moveToTop()));
    QObject::connect(actionMove_to_bottom, SIGNAL(triggered()), this, SLOT(moveToBottom()));
    QObject::connect(actionHide, SIGNAL(triggered()), this, SLOT(hideQuestion()));
    QObject::connect(actionShow_hidden, SIGNAL(triggered()), this, SLOT(filterLQSearch()));

    rbtngrpFilterLQ = new QButtonGroup(this);
    rbtngrpFilterLQ->addButton(LQAllRadioButton);
    rbtngrpFilterLQ->addButton(LQEasyRadioButton);
    rbtngrpFilterLQ->addButton(LQMediumRadioButton);
    rbtngrpFilterLQ->addButton(LQDifficultRadioButton);
    rbtngrpFilterLQ->addButton(LQCategoryRadioButton);

    actgrpFilterLQ = new QActionGroup(this);
    actgrpFilterLQ->addAction(actionShow_all);
    actgrpFilterLQ->addAction(actionShow_easy);
    actgrpFilterLQ->addAction(actionShow_medium);
    actgrpFilterLQ->addAction(actionShow_difficult);
    actgrpFilterLQ->addAction(actionShow_category);

    QObject::connect(rbtngrpFilterLQ, SIGNAL(buttonReleased(QAbstractButton *)), this, SLOT(filterLQ(QAbstractButton *)));
    QObject::connect(actgrpFilterLQ, SIGNAL(triggered(QAction *)), this, SLOT(filterLQAction(QAction *)));
    QObject::connect(LQCategoryComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterLQCategoryChanged()));
    QObject::connect(LQSearchLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterLQSearch()));
    QObject::connect(tbtnSearchByGroup, SIGNAL(released()), this, SLOT(searchByGroup()));

    actgrpPage = new QActionGroup(this);
    actgrpPage->addAction(actionEdit_questions);
    actgrpPage->addAction(actionEdit_comments);
    actgrpPage->addAction(actionEdit_categories);
    actgrpPage->addAction(actionEdit_test);
    actgrpPage->addAction(actionSaved_sessions);
    actgrpPage->addAction(actionEdit_classes);

    QObject::connect(actgrpPage, SIGNAL(triggered(QAction *)), this, SLOT(setPage(QAction *)));

    //QObject::connect(btnApply, SIGNAL(released()), this, SLOT(setDatabaseModified()));
    //QObject::connect(actionApply, SIGNAL(triggered()), this, SLOT(setDatabaseModified()));
    QObject::connect(ECTextEdit, SIGNAL(textChanged()), this, SLOT(setDatabaseModified()));

    QObject::connect(actionCheck_for_updates, SIGNAL(triggered()), this, SLOT(checkForUpdates()));
    QObject::connect(network_access_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(httpRequestFinished(QNetworkReply *)));
    QObject::connect(actionDocumentation, SIGNAL(triggered()), this, SLOT(openDocumentation()));
    QObject::connect(SQStatisticsLabel, SIGNAL(linkActivated(QString)), this, SLOT(adjustQuestionDifficulty()));
    QObject::connect(actionPrint_questions, SIGNAL(triggered()), this, SLOT(showPrintQuestionsDialogue()));
    QObject::connect(actionOverall_statistics, SIGNAL(triggered()), this, SLOT(overallStatistics()));
    QObject::connect(actionChange_language, SIGNAL(triggered()), this, SLOT(changeLanguage()));

    QObject::connect(mainStackedWidget, SIGNAL(currentChanged(int)), this, SLOT(currentPageChanged(int)));
    // Disable all -------------------------------------------------------------
    setAllEnabled(false);
    // Categories -------------------------------------------------------------------
    setupCategoriesPage();
    // Server ------------------------------------------------------------------
    setupServer();
    // Session viewer ----------------------------------------------------------
    setupSessionViewer();
    // Class viewer ------------------------------------------------------------
    setupClassViewer();
    // -------------------------------------------------------------------------
#ifdef Q_OS_MAC
    show();
#endif
    // Load settings -----------------------------------------------------------
    loadSettings();
    // Ready -------------------------------------------------------------------
    statusBar()->showMessage(tr("Ready"), 10000);
    // Check app args ----------------------------------------------------------
    if (qApp->arguments().count() > 1) {
        openFile(qApp->arguments().at(1));
    }
    // -------------------------------------------------------------------------
#ifndef Q_OS_MAC
    show();
#endif
}
Example #2
0
void MainWindow::openDB(const QString &openDBName, bool useCP1250)
{
    if (openDBName.isNull())
        return;
    this->setEnabled(false); qApp->processEvents();
    try {
        QFile file(openDBName);
        if (!file.open(QFile::ReadOnly | QFile::Text)) {
            QMessageBox::critical(this, tr("Open database"), tr("Cannot read file %1:\n%2.").arg(openDBName).arg(file.errorString()));
            this->setEnabled(true); return;
        }
        setProgress(3); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        QTextStream rfile(&file);
        if (useCP1250) {
            rfile.setCodec("CP 1250");
        } else {
            rfile.setCodec("UTF-8");
        }

        QString db_buffer;
        QStringList bufferlist;
        // ---------------------------------------------------------------------
        if (rfile.readLine() != "[ITEST_VERSION]") { throw xInvalidDBFile(0); }
        rfile.readLine();
        if (rfile.readLine() != "[ITEST_DB_VERSION]") { throw xInvalidDBFile(1); }
        double db_version = rfile.readLine().toDouble();
        if (db_version > F_ITDB_VERSION) {
            QMessageBox::critical(this, tr("iTest version notice"), tr("You need a newer version of iTest to open this database file."));
            this->setEnabled(true);
            return;
        }
        if (!useCP1250) {
            if (db_version == 1.0) {
                openDB(openDBName, true);
                return;
            }
        }

        if (rfile.readLine() != "[DB_NAME]") { throw xInvalidDBFile(10); }
        // Database name
        QString db_name = rfile.readLine();
        if (rfile.readLine() != "[DB_DATE]") { throw xInvalidDBFile(12); }
        // Database date
        QString db_date = rfile.readLine();
        if (rfile.readLine() != "[DB_DATE_ULSD]") { throw xInvalidDBFile(14); }
        // Use last save date
        rfile.readLine();
        if (rfile.readLine() != "[DB_COMMENTS]") { throw xInvalidDBFile(16); }
        // Database comments
        QString db_comments = rfile.readLine();
        if (rfile.readLine() != "[DB_QNUM]") { throw xInvalidDBFile(18); }
        // Question number
        int db_qnum = rfile.readLine().toInt();
        if (rfile.readLine() != "[DB_SNUM]") { throw xInvalidDBFile(20); }
        // Number of saved sessions
        int db_snum = rfile.readLine().toInt();
        int db_cnum = 0;
        if (db_version >= 1.35) {
            if (rfile.readLine() != "[DB_CNUM]") { throw xInvalidDBFile(22); }
            // Number of classes
            db_cnum = rfile.readLine().toInt();
        }
        if (rfile.readLine() != "[DB_FLAGS]") { throw xInvalidDBFile(50); }
        setProgress(6); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        // Categories enabled
        db_buffer = rfile.readLine();
        QVector<bool> db_categories_enabled(db_buffer.length());
        for (int i = 0; i < db_categories_enabled.size(); ++i) {
            if (db_buffer.at(i) == '+') {
                db_categories_enabled[i] = true;
            } else if (db_buffer.at(i) == '-') {
                db_categories_enabled[i] = false;
            } else {
                throw xInvalidDBFile(52);
            }
        }
        // Categories
        QVector<QString> db_categories(db_buffer.length());
        for (int i = 0; i < db_categories.size(); ++i) {
            if (rfile.readLine() != QString("[DB_F%1]").arg(i)) { throw xInvalidDBFile(54); }
            db_categories[i] = rfile.readLine();
        }
        // End of categories
        if (rfile.readLine() != "[DB_FLAGS_END]") { throw xInvalidDBFile(59); }
        setProgress(10); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        int count = db_qnum + db_snum;
        // Questions
        QuestionItem *item;
        QStringList answers;
        for (int i = 0; i < db_qnum; ++i) {
            answers.clear();
            // Question name
            if (rfile.readLine() != "[Q_NAME]") { throw xInvalidDBFile(100); }
            item = new QuestionItem (rfile.readLine());
            // Category
            if (rfile.readLine() != "[Q_FLAG]") { throw xInvalidDBFile(102); }
            item->setCategory(rfile.readLine().toInt());
            if (db_version >= 1.2) {
                // Question group
                if (rfile.readLine() != "[Q_GRP]") { throw xInvalidDBFile(104); }
                item->setGroup(rfile.readLine());
            }
            // Difficulty
            if (db_version >= 1.2) {
                if (rfile.readLine() != "[Q_DIF]") { throw xInvalidDBFile(106); }
            } else {
                if (rfile.readLine() != "[Q_DIFFICULTY]") { throw xInvalidDBFile(108); }
            }
            item->setDifficulty(rfile.readLine().toInt());
            // Question text
            if (rfile.readLine() != "[Q_TEXT]") { throw xInvalidDBFile(110); }
            item->setText(rfile.readLine());
            if (db_version >= 1.35) {
                // Answers
                if (rfile.readLine() != "[Q_ANS]") { throw xInvalidDBFile(112); }
                item->setSelectionType((Question::SelectionType)rfile.readLine().toInt());
                item->setCorrectAnswers((Question::Answer)rfile.readLine().toInt());
                int numanswers = rfile.readLine().toInt();
                for (int a = 0; a < numanswers; ++a) { answers << rfile.readLine(); }
                // Explanation
                if (rfile.readLine() != "[Q_EXPL]") { throw xInvalidDBFile(114); }
                item->setExplanation(rfile.readLine());
            } else {
                // Answer A
                if (rfile.readLine() != "[Q_ANSA]") { throw xInvalidDBFile(116); }
                answers << rfile.readLine();
                if (db_version < 1.2) {
                    if (rfile.readLine() != "[Q_ANSA_C]") { throw xInvalidDBFile(118); }
                }
                item->setAnswerCorrect(Question::A, rfile.readLine() == "true");
                // Answer B
                if (rfile.readLine() != "[Q_ANSB]") { throw xInvalidDBFile(120); }
                answers << rfile.readLine();
                if (db_version < 1.2) {
                    if (rfile.readLine() != "[Q_ANSB_C]") { throw xInvalidDBFile(122); }
                }
                item->setAnswerCorrect(Question::B, rfile.readLine() == "true");
                // Answer C
                if (rfile.readLine() != "[Q_ANSC]") { throw xInvalidDBFile(124); }
                answers << rfile.readLine();
                if (db_version < 1.2) {
                    if (rfile.readLine() != "[Q_ANSC_C]") { throw xInvalidDBFile(126); }
                }
                item->setAnswerCorrect(Question::C, rfile.readLine() == "true");
                // Answer D
                if (rfile.readLine() != "[Q_ANSD]") { throw xInvalidDBFile(128); }
                answers << rfile.readLine();
                if (db_version < 1.2) {
                    if (rfile.readLine() != "[Q_ANSD_C]") { throw xInvalidDBFile(130); }
                }
                item->setAnswerCorrect(Question::D, rfile.readLine() == "true");
            }
            // Statistics
            if (db_version < 1.2) {
                if (rfile.readLine() != "[Q_ICNT]") { throw xInvalidDBFile(132); }
            } else {
                if (rfile.readLine() != "[Q_ICCNT]") { throw xInvalidDBFile(134); }
            }
            item->setIncorrectAnsCount(rfile.readLine().toUInt());
            if (db_version < 1.2) {
                if (rfile.readLine() != "[Q_CCNT]") { throw xInvalidDBFile(136); }
            }
            item->setCorrectAnsCount(rfile.readLine().toUInt());
            // Hidden
            if (db_version >= 1.2) {
                if (rfile.readLine() != "[Q_HID]") { throw xInvalidDBFile(138); }
                item->setHidden(rfile.readLine() == "true");
            }
            if (db_version > 1.25) {
                // SVG
                if (rfile.readLine() != "[Q_SVG]") { throw xInvalidDBFile(140); }
                int numsvgitems = rfile.readLine().toInt();
                for (int g = 0; g < numsvgitems; ++g) {
                    db_buffer = rfile.readLine();
                    item->addSvgItem(new SvgItem(db_buffer, rfile.readLine()));
                }
            }
            // End
            if (db_version < 1.25) {
                if (rfile.readLine() != "[Q_END]") { throw xInvalidDBFile(199); }
            }
            // Add map entry
            item->setAnswers(answers);
            QListWidgetItem *q_item = new QListWidgetItem (item->group().isEmpty() ? item->name() : QString("[%1] %2").arg(item->group()).arg(item->name()));
            LQListWidget->addItem(q_item);
            current_db_questions.insert(q_item, item);
            setQuestionItemIcon(q_item, item->difficulty());
            setQuestionItemColour(q_item, item->category());
            hideQuestion(q_item, item);
            setProgress((85/(i+1)*count)+10); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>
        }
        // Saved sessions
        int ans_category = -1;
        int ans_dif = 0;
        Question::Answer c_ans;
        Question::Answer ans;
        Question::SelectionType ans_selectiontype = Question::SingleSelection;
        for (int i = 0; i < db_snum; ++i) {
            if (rfile.atEnd())
                break;
            if (rfile.readLine() != "[SESSION]")
                continue;
            Session *session = new Session;
            session->setName(rfile.readLine());
            session->setDateTimeFromString(rfile.readLine());
            if (db_version >= 1.2) {
                if (rfile.readLine() != "[PASSMARK]") { throw xInvalidDBFile(202); }
                PassMark pm(rfile.readLine().toInt());
                int pm_count = rfile.readLine().toInt();
                int pm_c, pm_v;
                for (int i = 0; i < pm_count; ++i) {
                    pm_c = rfile.readLine().toInt();
                    pm_v = rfile.readLine().toInt();
                    pm.addCondition(pm_c, pm_v, pm_v);
                }
                session->setPassMark(pm);
            } else {
                session->setPassMark(PassMark(rfile.readLine().toInt()));
            }
            ScoringSystem sys;
            if (db_version >= 1.35) {
                db_buffer = rfile.readLine(); db_buffer.append("\n");
                db_buffer.append(rfile.readLine()); db_buffer.append("\n");
                db_buffer.append(rfile.readLine());
                sys.loadData(db_buffer);
            }
            int s_snum = rfile.readLine().toInt();
            int s_lenum = rfile.readLine().toInt();
            for (int le = 0; le < s_lenum; ++le) {
                bufferlist.clear();
                bufferlist = rfile.readLine().split(';');
                if (bufferlist.count() == 6) {
                    session->addLogEntry(bufferlist.at(0).toInt(),
                                         bufferlist.at(1).toInt(),
                                         bufferlist.at(2).toInt(),
                                         bufferlist.at(3).toInt(),
                                         bufferlist.at(4).toInt(),
                                         bufferlist.at(5).toInt(),
                                         rfile.readLine());
                } else {
                    session->addLogEntry(255, 255, 255, 0, 0, 0, rfile.readLine());
                }
            }
            for (int s = 0; s < s_snum; ++s) {
                if (rfile.atEnd())
                    break;
                if (rfile.readLine() != "[STUDENT]")
                    continue;
                Student *student = new Student(rfile.readLine());
                student->setReady(rfile.readLine() == "true");
                if (db_version >= 1.2) {
                    student->setPassed(rfile.readLine() == "true");
                }
                student->setNumber(rfile.readLine().toInt());
                if (db_version < 1.35) {
                    rfile.readLine(); // SCORE
                }
                int numresults = rfile.readLine().toInt();
                QMap<QString, QuestionAnswer> *results = new QMap<QString, QuestionAnswer>;
                for (int a = 0; a < numresults; ++a) {
                    db_buffer = rfile.readLine();
                    if (db_version >= 1.2) {
                        ans_category = rfile.readLine().toInt();
                    }

                    QuestionItem *item = NULL;
                    QMapIterator<QListWidgetItem *, QuestionItem *> q(current_db_questions);
                    while (q.hasNext()) { q.next();
                        if (q.value()->name() == db_buffer) {
                            item = q.value();
                            break;
                        }
                    }

                    if (db_version >= 1.35) {
                        ans_dif = rfile.readLine().toInt();
                        ans_selectiontype = (Question::SelectionType)rfile.readLine().toInt();
                    } else {
                        if (item == NULL) {
                            if (db_version < 1.2) {
                                ans_category = -1;
                            }
                            if (db_version < 1.35) {
                                ans_dif = 0;
                                ans_selectiontype = Question::SingleSelection;
                            }
                        } else {
                            if (db_version < 1.2) {
                                ans_category = item->category();
                            }
                            if (db_version < 1.35) {
                                ans_dif = item->difficulty();
                                ans_selectiontype = item->selectionType();
                            }
                        }
                    }

                    if (db_version < 1.27) {
                        ans = Question::convertOldAnsNumber(rfile.readLine().toInt());
                        c_ans = Question::convertOldAnsNumber(rfile.readLine().toInt());
                    } else {
                        ans = (Question::Answer)rfile.readLine().toInt();
                        c_ans = (Question::Answer)rfile.readLine().toInt();
                    }

                    QuestionAnswer qans(c_ans, ans, item ? item->numAnswers() : 9, ans_category, ans_dif, ans_selectiontype);
                    results->insert(db_buffer, qans);
                }
                student->setResults(results);
                student->updateScore(sys);
                if (db_version < 1.2) {
                    student->setPassed(session->passMark().check(student->results(), &current_db_questions, sys));
                }
                session->addStudent(student);
            }
            session->setScoringSystem(sys);
            current_db_sessions.insert(session->dateTime(), session);
            QListWidgetItem *item = new QListWidgetItem (QString("%1 - %2").arg(session->dateTimeToString()).arg(session->name()));
            SVLSListWidget->insertItem(0, item);
            item->setData(Qt::UserRole, session->dateTime());
            setProgress((85/(db_qnum+i+1)*count)+10); // PROGRESS >>>>>>>>>>>>>>
        }
        // Classes
        for (int i = 0; i < db_cnum; ++i) {
            if (rfile.atEnd())
                break;
            if (rfile.readLine() != "[CLASS]")
                continue;
            Class *cl = new Class(rfile.readLine());
            bufferlist = rfile.readLine().split("-", QString::SkipEmptyParts);
            cl->setFirstYear(bufferlist.at(0).toInt());
            cl->setLastYear(bufferlist.at(1).toInt());
            QStringList cl_sessions = rfile.readLine().split(";", QString::SkipEmptyParts);
            for (int s = 0; s < cl_sessions.count(); ++s) {
                cl->addSession(cl_sessions.at(s));
            }
            int mnum = rfile.readLine().toInt();
            for (int m = 0; m < mnum; ++m) {
                if (rfile.readLine() != "[MEM]")
                    continue;
                ClassMember *mem = new ClassMember(rfile.readLine());
                int msnum = rfile.readLine().toInt();
                for (int ms = 0; ms < msnum; ++ms) {
                    db_buffer = rfile.readLine();
                    mem->addSession(db_buffer, rfile.readLine().toInt());
                }
                cl->addMember(mem);
            }
            QListWidgetItem *cl_item = new QListWidgetItem(QString("%1-%2: %3").arg(cl->firstYear()).arg(cl->lastYear()).arg(cl->name()), CLLCListWidget);
            current_db_classes.insert(cl_item, cl);
        }

        ECTextEdit->setHtml( db_comments );
        // Set categories
        current_db_categories_enabled = db_categories_enabled;
        current_db_categories = db_categories;
        setProgress(97); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        // Apply categories
        setCategories(); loadCategories();
        setProgress(98); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        // Enable All
        setAllEnabled(true);
        setProgress(99); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        // Save values
        current_db_file = openDBName;
        current_db_comments = db_comments;
        current_db_open = true;
#ifdef Q_OS_MAC
        this->setWindowTitle(QString("%1[*]").arg(currentDatabaseName()));
#else
        this->setWindowTitle(QString("%1[*] - iTestServer").arg(currentDatabaseName()));
#endif
        this->setWindowModified(false);
        statusBar()->showMessage(tr("Database open"), 10000);
        setProgress(100); setProgress(-1); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>
        actionEdit_questions->setChecked(true);
        mainStackedWidget->setCurrentIndex(1);
        // ---------------------------------------------------------------------
        this->setEnabled(true);
    }
    catch (xInvalidDBFile e) {
        errorInvalidDBFile(tr("Open database"), openDBName, e.error());
    }
    catch (...) {
        QMessageBox::critical(this, tr("iTestServer"), tr("Error opening database."));
        clearAll(); setAllEnabled(false); current_db_open = false;
        this->setWindowTitle(tr("iTestServer"));
        this->setWindowModified(false); setProgress(-1);
        mainStackedWidget->setCurrentIndex(0);
        this->setEnabled(true);
    }
}