コード例 #1
0
ファイル: main_window.cpp プロジェクト: gz818/itest
void MainWindow::setCurrentQuestion()
{
     if (LQListWidget->currentIndex().isValid()) {
        questionTextBrowser->clear();
        answersView->setEnabled(true);
        QuestionItem *item = current_test_questions.value(LQListWidget->currentItem());
        questionTextBrowser->setHtml(item->text());
        answersView->setAnswers(item->answers(), item->answered(), item->selectionType(), item->answerOrder());
        svgDisplayWidget->clear();
        if (item->numSvgItems() > 0) {
            svgDisplayWidget->setVisible(true);
            //int h = 0;
            for (int i = 0; i < item->numSvgItems(); ++i) {
                QSvgWidget *svg_widget = new QSvgWidget;
                QSize minimum_size = svg_widget->sizeHint();
                minimum_size.scale(128, 128, Qt::KeepAspectRatioByExpanding);
                svg_widget->setMinimumSize(minimum_size);
                svg_widget->load(item->svg(i).toUtf8());
                /*if (svg_widget->renderer()->defaultSize().height() + 40 > h) {
                    h = svg_widget->renderer()->defaultSize().height() + 40;
                }*/
                svgDisplayWidget->addWidget(svg_widget, item->svgName(i), true);
            }
            //if (h < 168) { h = 168; }
            qApp->processEvents();
            questionTextSvgSplitter->moveSplitter(questionTextSvgSplitter->height()-svgDisplayWidget->layoutHeightForWidth(questionTextSvgSplitter->width()));
        } else {
            svgDisplayWidget->setVisible(false);
        }
        if (LQListWidget->currentRow() >= (LQListWidget->count()-1)) {
            btnNext->setEnabled(false);
        } else {
            btnNext->setEnabled(true);
        }
        if (LQListWidget->currentRow() <= 0) {
            btnLast->setEnabled(false);
        } else {
            btnLast->setEnabled(true);
        }
     } else {
        questionTextBrowser->clear();
        answersView->clear();
        answersView->setEnabled(false);
        svgDisplayWidget->clear();
        btnNext->setEnabled(false);
        btnLast->setEnabled(false);
     }
}
コード例 #2
0
ファイル: database.cpp プロジェクト: flysky217/itest
void MainWindow::exportCSV()
{
    QString file_name = QFileDialog::getSaveFileName(this,
                                                     tr("Export as CSV"),
                                                     QString("%1.csv").arg(currentDatabaseName()),
                                                     tr("CSV files (*.csv)"));
    if (file_name.isEmpty())
        return;

    QFile file(file_name);
    if (!file.open(QFile::WriteOnly | QFile::Text)) {
        QMessageBox::critical(this, tr("Export as CSV"), tr("Cannot write file %1:\n%2.").arg(file_name).arg(file.errorString()));
        this->setEnabled(true); return;
    }

    QTextStream out(&file);
    out.setCodec("UTF-8");

    const QString separator(',');

    QTextDocument doc;
    for (int i = 0; i < LQListWidget->count(); ++i) {
        QuestionItem *item = current_db_questions.value(LQListWidget->item(i));
        out << quoteForCSV(item->name()) << separator;
        out << QString::number(item->category()) << separator;
        out << quoteForCSV(item->group()) << separator;
        doc.setHtml(item->text());
        out << quoteForCSV(doc.toPlainText()) << separator;
        out << quoteForCSV(item->explanation()) << separator;
        out << QString::number(item->correctAnswers());
        foreach (const QString &answer, item->answers())
            out << separator << quoteForCSV(answer);
        out << endl;
    }

    file.close();
}