KProgress::KProgress(int totalSteps, QWidget *parent, const char *name, WFlags f) : QProgressBar(totalSteps, parent, name, f), mFormat("%p%") { setProgress(0); }
void QFListProgressDialog::setMajorProgress(int value) { setProgress(value); }
/* helper methods */ void ThermalCalibrationHelper::updateTemperature(float temp) { int elapsed = m_startTime.secsTo(QTime::currentTime()); int secondsSinceLastCheck = m_lastCheckpointTime.secsTo(QTime::currentTime()); // temperature is low pass filtered m_temperature = m_temperature * 0.95f + temp * 0.05f; emit temperatureChanged(m_temperature); // temperature range if (m_temperature < m_minTemperature) { m_minTemperature = m_temperature; } if (m_temperature > m_maxTemperature) { m_maxTemperature = m_temperature; } if (!m_rangeReached && (range() >= TargetTempDelta)) { m_rangeReached = true; addInstructions(tr("Target temperature span has been acquired. Acquisition may be ended or, preferably, continued.")); } emit temperatureRangeChanged(range()); if (secondsSinceLastCheck > TimeBetweenCheckpoints) { // gradient is expressed in °C/min m_gradient = 60.0 * (m_temperature - m_lastCheckpointTemp) / (float)secondsSinceLastCheck; emit temperatureGradientChanged(gradient()); qDebug() << "Temp Gradient " << gradient() << " Elapsed" << elapsed; m_debugStream << "INFO::Trace Temp Gradient " << gradient() << " Elapsed" << elapsed << endl; m_lastCheckpointTime = QTime::currentTime(); m_lastCheckpointTemp = m_temperature; } // at least a checkpoint has been reached if (elapsed > TimeBetweenCheckpoints) { // .1 is a "very" small value in this case thats > 0 if (m_initialGradient < .1 && m_gradient > .1) { m_initialGradient = m_gradient; } if (m_targetduration != 0) { int tmp = (100 * elapsed) / m_targetduration; setProgress(tmp); } else if ((m_gradient > .1) && ((m_initialGradient / 2.0f) > m_gradient)) { // make a rough estimation of the time needed m_targetduration = elapsed * 8; setProgressMax(100); QTime time = QTime(0, 0).addSecs(m_targetduration); QString timeString = time.toString(tr("m''s''''")); addInstructions(tr("Estimated acquisition duration is %1.").arg(timeString)); QString str = QStringLiteral("INFO::Trace gradient : %1, elapsed : %2 initial gradient : %3, target : %4") .arg(m_gradient).arg(elapsed).arg(m_initialGradient).arg(m_targetduration); qDebug() << str; m_debugStream << str << endl; } if ((m_gradient < TargetGradient) || m_forceStopAcquisition) { m_acquiring = false; emit collectionCompleted(); } } }
void report (const String& status, Real progress) { setStatus(status); setProgress(progress); }
void MgNeuralNetworkAnimator::setProgressAndUpdate(int p) { setProgress(p); update(); }
unsigned int ProgressMonitor::operator++() { setProgress(_progress + 1); return _progress; }
void PlanTJScheduler::run() { if ( m_haltScheduling ) { deleteLater(); return; } if ( m_stopScheduling ) { return; } setMaxProgress( PROGRESS_MAX_VALUE ); { // mutex --> m_projectMutex.lock(); m_managerMutex.lock(); m_project = new Project(); loadProject( m_project, m_pdoc ); m_project->setName( "Schedule: " + m_project->name() ); //Debug m_project->stopcalculation = false; m_manager = m_project->scheduleManager( m_mainmanagerId ); Q_CHECK_PTR( m_manager ); Q_ASSERT( m_manager->expected() ); Q_ASSERT( m_manager != m_mainmanager ); Q_ASSERT( m_manager->scheduleId() == m_mainmanager->scheduleId() ); Q_ASSERT( m_manager->expected() != m_mainmanager->expected() ); m_manager->setName( "Schedule: " + m_manager->name() ); //Debug m_schedule = m_manager->expected(); bool x = connect(m_manager, SIGNAL(sigLogAdded(Schedule::Log)), this, SLOT(slotAddLog(Schedule::Log))); Q_ASSERT( x ); m_project->initiateCalculation( *m_schedule ); m_project->initiateCalculationLists( *m_schedule ); m_usePert = m_manager->usePert(); m_recalculate = m_manager->recalculate(); if ( m_recalculate ) { m_backward = false; } else { m_backward = m_manager->schedulingDirection(); } m_project->setCurrentSchedule( m_manager->expected()->id() ); m_schedule->setPhaseName( 0, i18nc( "@info/plain" , "Init" ) ); if ( ! m_backward && locale() ) { logDebug( m_project, 0, QString( "Schedule project using TJ Scheduler, starting at %1, granularity %2" ).arg( QDateTime::currentDateTime().toString() ).arg( locale()->formatDuration( m_granularity ) ), 0 ); if ( m_recalculate ) { logInfo( m_project, 0, i18nc( "@info/plain" , "Re-calculate project from start time: %1", locale()->formatDateTime( m_project->constraintStartTime() ) ), 0 ); } else { logInfo( m_project, 0, i18nc( "@info/plain" , "Schedule project from start time: %1", locale()->formatDateTime( m_project->constraintStartTime() ) ), 0 ); } logInfo( m_project, 0, i18nc( "@info/plain" , "Project target finish time: %1", locale()->formatDateTime( m_project->constraintEndTime() ) ), 0 ); } if ( m_backward && locale() ) { logDebug( m_project, 0, QString( "Schedule project backward using TJ Scheduler, starting at %1, granularity %2" ).arg( locale()->formatDateTime( QDateTime::currentDateTime() ) ).arg( locale()->formatDuration( m_granularity ) ), 0 ); logInfo( m_project, 0, i18nc( "@info/plain" , "Schedule project from end time: %1", locale()->formatDateTime( m_project->constraintEndTime() ) ), 0 ); } m_managerMutex.unlock(); m_projectMutex.unlock(); } // <--- mutex setProgress( 2 ); if ( ! kplatoToTJ() ) { result = 1; setProgress( PROGRESS_MAX_VALUE ); return; } setMaxProgress( PROGRESS_MAX_VALUE ); connect(m_tjProject, SIGNAL(updateProgressBar(int,int)), this, SLOT(setProgress(int))); m_schedule->setPhaseName( 1, i18nc( "@info/plain" , "Schedule" ) ); logInfo( m_project, 0, "Start scheduling", 1 ); bool r = solve(); if ( ! r ) { kDebug(planDbg())<<"Scheduling failed"; result = 2; logError( m_project, 0, i18nc( "@info/plain" , "Failed to schedule project" ) ); setProgress( PROGRESS_MAX_VALUE ); return; } if ( m_haltScheduling ) { kDebug(planDbg())<<"Scheduling halted"; logInfo( m_project, 0, "Scheduling halted" ); deleteLater(); return; } m_schedule->setPhaseName( 2, i18nc( "@info/plain" , "Update" ) ); logInfo( m_project, 0, "Scheduling finished, update project", 2 ); if ( ! kplatoFromTJ() ) { logError( m_project, 0, "Project update failed" ); } setProgress( PROGRESS_MAX_VALUE ); m_schedule->setPhaseName( 3, i18nc( "@info/plain" , "Finish" ) ); }
void MainWindow::saveDB(const QString &db_file_name, bool savecopy) { this->setEnabled(false); qApp->processEvents(); // Prepare if (LQListWidget->currentIndex().isValid()) { applyQuestionChanges(); } // Gather info bool itdb1_3 = db_file_name.endsWith(".it13.itdb"); QString db_comments = removeLineBreaks(ECTextEdit->toHtml()); uint db_snum = (uint)current_db_sessions.size(); // Save database ----------------------------------------------------------- QFile file(db_file_name); if (!file.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::critical(this, tr("Save database"), tr("Cannot write file %1:\n%2.").arg(db_file_name).arg(file.errorString())); this->setEnabled(true); return; } setProgress(5); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> QTextStream sfile(&file); sfile.setCodec("UTF-8"); sfile << "[ITEST_VERSION]\n" << F_ITEST_VERSION << endl; sfile << "[ITEST_DB_VERSION]\n" << (itdb1_3 ? 1.3 : F_ITDB_VERSION) << endl; sfile << "[DB_NAME]\n" << databaseNameForFilePath(db_file_name) << endl; sfile << "[DB_DATE]\n" << QDateTime::currentDateTime().toString("yyyy.MM.dd-hh:mm") << endl; sfile << "[DB_DATE_ULSD]\ntrue" << endl; sfile << "[DB_COMMENTS]\n" << db_comments << endl; sfile << "[DB_QNUM]\n" << current_db_questions.size() << endl; sfile << "[DB_SNUM]\n" << (itdb1_3 ? 0 : db_snum) << endl; if (!itdb1_3) sfile << "[DB_CNUM]\n" << current_db_classes.size() << endl; sfile << "[DB_FLAGS]" << endl; int num_categories = current_db_categories.size(); if (num_categories > 20 && !current_db_categories_enabled[num_categories - 1]) num_categories--; for (int i = 0; i < num_categories; ++i) { sfile << (current_db_categories_enabled[i] ? "+" : "-"); } sfile << endl; for (int i = 0; i < num_categories; ++i) { sfile << "[DB_F" << i << "]\n" << current_db_categories[i] << endl; } sfile << "[DB_FLAGS_END]" << endl; setProgress(10); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> uint count = (uint)current_db_questions.size() + (uint)current_db_sessions.size(); uint n = current_db_questions.size(); for (int i = 0; i < LQListWidget->count(); ++i) { sfile << current_db_questions.value(LQListWidget->item(i))->allProperties(itdb1_3) << endl; setProgress((90/(i+1)*count)+10); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>> } if (!itdb1_3) { QMapIterator<QDateTime, Session *> i(current_db_sessions); while (i.hasNext()) { i.next(); n++; sfile << i.value()->sessionData() << endl; for (int s = 0; s < i.value()->numStudents(); ++s) { sfile << i.value()->student(s)->studentData() << endl; } setProgress((90/n*count)+10); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> } QMapIterator<QListWidgetItem *, Class *> c(current_db_classes); while (c.hasNext()) { c.next(); sfile << c.value()->classData() << endl; } } // ------------------------------------------------------------------------- if (!savecopy) { current_db_comments = db_comments; current_db_file = db_file_name; } #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 saved"), 10000); setProgress(100); setProgress(-1); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>> // ------------------------------------------------------------------------- this->setEnabled(true); }
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(), ¤t_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); } }
void Q3ProgressDialog::setProgress(int progress, int totalSteps) { setTotalSteps(totalSteps); setProgress(progress); }
void AverageLinkage::operator()(DistanceMatrix<float> & original_distance, std::vector<BinaryTreeNode> & cluster_tree, const float threshold /*=1*/) const { // input MUST have >= 2 elements! if (original_distance.dimensionsize() < 2) { throw ClusterFunctor::InsufficientInput(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Distance matrix to start from only contains one element"); } std::vector<std::set<Size> > clusters(original_distance.dimensionsize()); for (Size i = 0; i < original_distance.dimensionsize(); ++i) { clusters[i].insert(i); } cluster_tree.clear(); cluster_tree.reserve(original_distance.dimensionsize() - 1); // Initial minimum-distance pair original_distance.updateMinElement(); std::pair<Size, Size> min = original_distance.getMinElementCoordinates(); Size overall_cluster_steps(original_distance.dimensionsize()); startProgress(0, original_distance.dimensionsize(), "clustering data"); while (original_distance(min.second, min.first) < threshold) { //grow the tree cluster_tree.push_back(BinaryTreeNode(*(clusters[min.second].begin()), *(clusters[min.first].begin()), original_distance(min.first, min.second))); if (cluster_tree.back().left_child > cluster_tree.back().right_child) { std::swap(cluster_tree.back().left_child, cluster_tree.back().right_child); } if (original_distance.dimensionsize() > 2) { //pick minimum-distance pair i,j and merge them //calculate parameter for lance-williams formula float alpha_i = (float)(clusters[min.first].size() / (float)(clusters[min.first].size() + clusters[min.second].size())); float alpha_j = (float)(clusters[min.second].size() / (float)(clusters[min.first].size() + clusters[min.second].size())); //~ std::cout << alpha_i << '\t' << alpha_j << std::endl; //pushback elements of second to first (and then erase second) clusters[min.second].insert(clusters[min.first].begin(), clusters[min.first].end()); // erase first one clusters.erase(clusters.begin() + min.first); //update original_distance matrix //average linkage: new distance between clusters is the minimum distance between elements of each cluster //lance-williams update for d((i,j),k): (m_i/m_i+m_j)* d(i,k) + (m_j/m_i+m_j)* d(j,k) ; m_x is the number of elements in cluster x for (Size k = 0; k < min.second; ++k) { float dik = original_distance.getValue(min.first, k); float djk = original_distance.getValue(min.second, k); original_distance.setValueQuick(min.second, k, (alpha_i * dik + alpha_j * djk)); } for (Size k = min.second + 1; k < original_distance.dimensionsize(); ++k) { float dik = original_distance.getValue(min.first, k); float djk = original_distance.getValue(min.second, k); original_distance.setValueQuick(k, min.second, (alpha_i * dik + alpha_j * djk)); } //reduce original_distance.reduce(min.first); //update minimum-distance pair original_distance.updateMinElement(); //get min-pair from triangular matrix min = original_distance.getMinElementCoordinates(); } else { break; } setProgress(overall_cluster_steps - original_distance.dimensionsize()); //repeat until only two cluster remains, last step skips matrix operations } //fill tree with dummy nodes Size sad(*clusters.front().begin()); for (Size i = 1; (i < clusters.size()) && (cluster_tree.size() < cluster_tree.capacity()); ++i) { cluster_tree.push_back(BinaryTreeNode(sad, *clusters[i].begin(), -1.0)); } endProgress(); }
void Splash::setProgressAndText(const std::string& text, float fraction) { setText(text); setProgress(fraction); }
// ### KDE 4 remove void KProgress::setValue(int progress) { setProgress(progress); }
void KProgress::advance(int offset) { setProgress(progress() + offset); }
void TransitionPQPReader::writePQPOutput_(const char* filename, OpenMS::TargetedExperiment& targeted_exp) { sqlite3 *db; char *zErrMsg = 0; int rc; // delete file if present remove(filename); // Open database rc = sqlite3_open(filename, &db); if ( rc ) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); } // Create SQL structure const char* create_sql = // protein table // OpenSWATH proteomics workflows "CREATE TABLE PROTEIN(" \ "ID INT PRIMARY KEY NOT NULL," \ "PROTEIN_ACCESSION TEXT NOT NULL," \ "DECOY INT NULL);" \ // peptide_protein_mapping table // OpenSWATH proteomics workflows "CREATE TABLE PEPTIDE_PROTEIN_MAPPING(" \ "PEPTIDE_ID INT NOT NULL," \ "PROTEIN_ID INT NOT NULL);" \ // peptide table // OpenSWATH proteomics workflows "CREATE TABLE PEPTIDE(" \ "ID INT PRIMARY KEY NOT NULL," \ "UNMODIFIED_SEQUENCE TEXT NOT NULL," \ "MODIFIED_SEQUENCE TEXT NOT NULL," \ "DECOY INT NOT NULL);" \ // precursor_peptide_mapping table // OpenSWATH proteomics workflows "CREATE TABLE PRECURSOR_PEPTIDE_MAPPING(" \ "PRECURSOR_ID INT NOT NULL," \ "PEPTIDE_ID INT NOT NULL);" \ // compound table // OpenSWATH metabolomics workflows "CREATE TABLE COMPOUND(" \ "ID INT PRIMARY KEY NOT NULL," \ "COMPOUND_NAME TEXT NOT NULL," \ "SUM_FORMULA TEXT NOT NULL," \ "SMILES TEXT NOT NULL," \ "DECOY INT NOT NULL);" \ // precursor_compound_mapping table // OpenSWATH metabolomics workflows "CREATE TABLE PRECURSOR_COMPOUND_MAPPING(" \ "PRECURSOR_ID INT NOT NULL," \ "COMPOUND_ID INT NOT NULL);" \ // precursor table "CREATE TABLE PRECURSOR(" \ "ID INT PRIMARY KEY NOT NULL," \ "TRAML_ID TEXT NULL," \ "GROUP_LABEL TEXT NULL," \ "PRECURSOR_MZ REAL NOT NULL," \ "CHARGE INT NULL," \ "LIBRARY_INTENSITY REAL NULL," \ "LIBRARY_RT REAL NULL," \ "DECOY INT NOT NULL);" \ // transition_precursor_mapping table "CREATE TABLE TRANSITION_PRECURSOR_MAPPING(" \ "TRANSITION_ID INT NOT NULL," \ "PRECURSOR_ID INT NOT NULL);" \ // transition_peptide_mapping table // IPF proteomics workflows "CREATE TABLE TRANSITION_PEPTIDE_MAPPING(" \ "TRANSITION_ID INT NOT NULL," \ "PEPTIDE_ID INT NOT NULL);" \ // transition table "CREATE TABLE TRANSITION(" \ "ID INT PRIMARY KEY NOT NULL," \ "TRAML_ID TEXT NULL," \ "PRODUCT_MZ REAL NOT NULL," \ "CHARGE INT NULL," \ "TYPE CHAR(1) NULL," \ "ORDINAL INT NULL," \ "DETECTING INT NOT NULL," \ "IDENTIFYING INT NOT NULL," \ "QUANTIFYING INT NOT NULL," \ "LIBRARY_INTENSITY REAL NULL," \ "DECOY INT NOT NULL);"; // Execute SQL create statement rc = sqlite3_exec(db, create_sql, callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Prepare insert statements // Index maps std::vector<std::string> group_set, peptide_set, compound_set, protein_set; std::map<int,double> precursor_mz_map; std::map<int,bool> precursor_decoy_map; std::stringstream insert_transition_sql, insert_transition_peptide_mapping_sql, insert_transition_precursor_mapping_sql; insert_transition_sql.precision(11); // OpenSWATH: Loop through TargetedExperiment to generate index maps for peptides Size progress = 0; startProgress(0, targeted_exp.getPeptides().size(), "Convert peptides"); for (Size i = 0; i < targeted_exp.getPeptides().size(); i++) { setProgress(progress++); OpenMS::TargetedExperiment::Peptide peptide = targeted_exp.getPeptides()[i]; std::string peptide_sequence = TargetedExperimentHelper::getAASequence(peptide).toString(); peptide_set.push_back(peptide_sequence); group_set.push_back(peptide.id); } endProgress(); // OpenSWATH: Loop through TargetedExperiment to generate index maps for compounds progress = 0; startProgress(0, targeted_exp.getCompounds().size(), "Convert compounds"); for (Size i = 0; i < targeted_exp.getCompounds().size(); i++) { setProgress(progress++); OpenMS::TargetedExperiment::Compound compound = targeted_exp.getCompounds()[i]; compound_set.push_back(compound.id); group_set.push_back(compound.id); } endProgress(); // OpenSWATH: Group set must be unique boost::erase(group_set, boost::unique<boost::return_found_end>(boost::sort(group_set))); // IPF: Loop through all transitions and generate peptidoform data structures progress = 0; std::vector<TransitionPQPReader::TSVTransition > transitions; startProgress(0, targeted_exp.getTransitions().size(), "Convert peptidoforms"); for (Size i = 0; i < targeted_exp.getTransitions().size(); i++) { setProgress(progress++); TransitionPQPReader::TSVTransition transition = convertTransition_(&targeted_exp.getTransitions()[i], targeted_exp); transitions.push_back(transition); std::copy( transition.peptidoforms.begin(), transition.peptidoforms.end(), std::inserter( peptide_set, peptide_set.end() ) ); int group_set_index = std::distance(group_set.begin(),std::find(group_set.begin(), group_set.end(), transition.group_id)); if (precursor_mz_map.find(group_set_index) == precursor_mz_map.end()) { precursor_mz_map[group_set_index] = transition.precursor; } if (precursor_decoy_map.find(group_set_index) == precursor_decoy_map.end()) { if (transition.detecting_transition == 1) { precursor_decoy_map[group_set_index] = transition.decoy; } } } endProgress(); // OpenSWATH: Peptide and compound sets must be unique boost::erase(peptide_set, boost::unique<boost::return_found_end>(boost::sort(peptide_set))); boost::erase(compound_set, boost::unique<boost::return_found_end>(boost::sort(compound_set))); // OpenSWATH: Prepare transition inserts progress = 0; startProgress(0, transitions.size(), String("Prepare ") + transitions.size() + " transitions and mapping"); for (Size i = 0; i < transitions.size(); i++) { setProgress(progress++); TransitionPQPReader::TSVTransition transition = transitions[i]; // IPF: Generate transition-peptide mapping tables (one identification transition can map to multiple peptidoforms) for (Size j = 0; j < transition.peptidoforms.size(); j++) { insert_transition_peptide_mapping_sql << "INSERT INTO TRANSITION_PEPTIDE_MAPPING (TRANSITION_ID, PEPTIDE_ID) VALUES (" << i << "," << std::distance(peptide_set.begin(),std::find(peptide_set.begin(), peptide_set.end(), transition.peptidoforms[j])) << "); "; } // OpenSWATH: Associate transitions with their precursors insert_transition_precursor_mapping_sql << "INSERT INTO TRANSITION_PRECURSOR_MAPPING (TRANSITION_ID, PRECURSOR_ID) VALUES (" << i << "," << std::distance(group_set.begin(), std::find(group_set.begin(), group_set.end(),transition.group_id)) << "); "; std::string transition_charge = "NULL"; // workaround for compounds with missing charge if (transition.fragment_charge != "NA") { transition_charge = transition.fragment_charge; } // OpenSWATH: Insert transition data insert_transition_sql << "INSERT INTO TRANSITION (ID, TRAML_ID, PRODUCT_MZ, CHARGE, TYPE, ORDINAL, DETECTING, IDENTIFYING, QUANTIFYING, LIBRARY_INTENSITY, DECOY) VALUES (" << i << ",'" << transition.transition_name << "'," << transition.product << "," << transition_charge << ",'" << transition.fragment_type<< "'," << transition.fragment_nr << "," << transition.detecting_transition << "," << transition.identifying_transition << "," << transition.quantifying_transition << "," << transition.library_intensity << "," << transition.decoy << "); "; } endProgress(); // OpenSWATH: Prepare protein inserts progress = 0; startProgress(0, targeted_exp.getProteins().size(), "Prepare protein mapping"); for (Size i = 0; i < targeted_exp.getProteins().size(); i++) { setProgress(progress++); OpenMS::TargetedExperiment::Protein protein = targeted_exp.getProteins()[i]; protein_set.push_back(protein.id); } endProgress(); boost::erase(protein_set, boost::unique<boost::return_found_end>(boost::sort(protein_set))); std::stringstream insert_precursor_sql, insert_precursor_peptide_mapping, insert_precursor_compound_mapping; insert_precursor_sql.precision(11); std::vector<std::pair<int, int> > peptide_protein_map; // OpenSWATH: Prepare peptide precursor inserts progress = 0; startProgress(0, targeted_exp.getPeptides().size(), "Prepare peptide precursors and mapping"); for (Size i = 0; i < targeted_exp.getPeptides().size(); i++) { setProgress(progress++); OpenMS::TargetedExperiment::Peptide peptide = targeted_exp.getPeptides()[i]; std::string peptide_sequence = TargetedExperimentHelper::getAASequence(peptide).toString(); int group_set_index = std::distance(group_set.begin(),std::find(group_set.begin(), group_set.end(), peptide.id)); int peptide_set_index = std::distance(peptide_set.begin(), std::find(peptide_set.begin(), peptide_set.end(), peptide_sequence)); for (std::vector<String>::iterator it = peptide.protein_refs.begin(); it != peptide.protein_refs.end(); ++it) { int protein_set_index = std::distance(protein_set.begin(),std::find(protein_set.begin(), protein_set.end(), *it)); peptide_protein_map.push_back(std::make_pair(peptide_set_index,protein_set_index)); } insert_precursor_sql << "INSERT INTO PRECURSOR (ID, TRAML_ID, GROUP_LABEL, PRECURSOR_MZ, CHARGE, LIBRARY_INTENSITY, LIBRARY_RT, DECOY) VALUES (" << group_set_index << ",'" << peptide.id << "','" << peptide.getPeptideGroupLabel() << "'," << precursor_mz_map[group_set_index] << "," << peptide.getChargeState() << ",NULL," << peptide.getRetentionTime() << "," << precursor_decoy_map[group_set_index] << "); "; insert_precursor_peptide_mapping << "INSERT INTO PRECURSOR_PEPTIDE_MAPPING (PRECURSOR_ID, PEPTIDE_ID) VALUES (" << group_set_index << "," << peptide_set_index << "); "; } endProgress(); // OpenSWATH: Prepare compound precursor inserts progress = 0; startProgress(0, targeted_exp.getCompounds().size(), "Prepare compound precursors and mapping"); for (Size i = 0; i < targeted_exp.getCompounds().size(); i++) { setProgress(progress++); OpenMS::TargetedExperiment::Compound compound = targeted_exp.getCompounds()[i]; int group_set_index = std::distance(group_set.begin(),std::find(group_set.begin(), group_set.end(), compound.id)); int compound_set_index = std::distance(compound_set.begin(), std::find(compound_set.begin(), compound_set.end(), compound.id)); std::string compound_charge = "NULL"; // workaround for compounds with missing charge if (compound.hasCharge()) { compound_charge = String(compound.getChargeState()); } insert_precursor_sql << "INSERT INTO PRECURSOR (ID, TRAML_ID, GROUP_LABEL, PRECURSOR_MZ, CHARGE, LIBRARY_INTENSITY, LIBRARY_RT, DECOY) VALUES (" << group_set_index << ",'" << compound.id << "',NULL," << precursor_mz_map[group_set_index] << "," << compound_charge << ",NULL,NULL" << "," << precursor_decoy_map[group_set_index] << "); "; insert_precursor_compound_mapping << "INSERT INTO PRECURSOR_COMPOUND_MAPPING (PRECURSOR_ID, COMPOUND_ID) VALUES (" << group_set_index << "," << compound_set_index << "); "; } endProgress(); boost::erase(peptide_protein_map, boost::unique<boost::return_found_end>(boost::sort(peptide_protein_map))); // OpenSWATH: Prepare peptide-protein mapping inserts std::stringstream insert_peptide_protein_mapping; progress = 0; startProgress(0, peptide_protein_map.size(), "Prepare peptide - protein mapping"); for (std::vector<std::pair<int, int> >::iterator it = peptide_protein_map.begin(); it != peptide_protein_map.end(); ++it) { setProgress(progress++); insert_peptide_protein_mapping << "INSERT INTO PEPTIDE_PROTEIN_MAPPING (PEPTIDE_ID, PROTEIN_ID) VALUES (" << it->first << "," << it->second << "); "; } endProgress(); // OpenSWATH: Prepare protein inserts std::stringstream insert_protein_sql; progress = 0; startProgress(0, protein_set.size(), String("Prepare ") + protein_set.size() + " proteins"); for (Size i = 0; i < protein_set.size(); i++) { setProgress(progress++); insert_protein_sql << "INSERT INTO PROTEIN (ID, PROTEIN_ACCESSION) VALUES (" << i << ",'" << protein_set[i] << "'); "; } endProgress(); // OpenSWATH: Prepare peptide inserts std::stringstream insert_peptide_sql; progress = 0; startProgress(0, peptide_set.size(), String("Prepare ") + peptide_set.size() + " peptides"); for (std::vector<std::string>::iterator it = peptide_set.begin(); it != peptide_set.end(); ++it) { setProgress(progress++); insert_peptide_sql << "INSERT INTO PEPTIDE (ID, UNMODIFIED_SEQUENCE, MODIFIED_SEQUENCE, DECOY) VALUES (" << std::distance(peptide_set.begin(),std::find(peptide_set.begin(), peptide_set.end(),*it)) << ",'" << AASequence::fromString(*it).toUnmodifiedString() << "','" << *it << "'," << 0 <<"); "; } endProgress(); // OpenSWATH: Prepare compound inserts std::stringstream insert_compound_sql; progress = 0; startProgress(0, compound_set.size(), String("Prepare ") + compound_set.size() + " compounds"); for (std::vector<std::string>::iterator it = compound_set.begin(); it != compound_set.end(); ++it) { setProgress(progress++); OpenMS::TargetedExperiment::Compound compound = targeted_exp.getCompoundByRef(*it); insert_compound_sql << "INSERT INTO COMPOUND (ID, COMPOUND_NAME, SUM_FORMULA, SMILES, DECOY) VALUES (" << std::distance(compound_set.begin(),std::find(compound_set.begin(), compound_set.end(),*it)) << ",'" << compound.id << "','" << compound.molecular_formula << "','" << compound.smiles_string << "'," << 0 <<"); "; } endProgress(); std::cout << "Write PQP file" << std::endl; sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &zErrMsg); // Execute SQL insert statement std::string insert_protein_sql_str = insert_protein_sql.str(); rc = sqlite3_exec(db, insert_protein_sql_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_peptide_protein_mapping_str = insert_peptide_protein_mapping.str(); rc = sqlite3_exec(db, insert_peptide_protein_mapping_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_peptide_sql_str = insert_peptide_sql.str(); rc = sqlite3_exec(db, insert_peptide_sql_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_compound_sql_str = insert_compound_sql.str(); rc = sqlite3_exec(db, insert_compound_sql_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_precursor_peptide_mapping_str = insert_precursor_peptide_mapping.str(); rc = sqlite3_exec(db, insert_precursor_peptide_mapping_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_precursor_compound_mapping_str = insert_precursor_compound_mapping.str(); rc = sqlite3_exec(db, insert_precursor_compound_mapping_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_precursor_sql_str = insert_precursor_sql.str(); rc = sqlite3_exec(db, insert_precursor_sql_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_transition_sql_str = insert_transition_sql.str(); rc = sqlite3_exec(db, insert_transition_sql_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_transition_peptide_mapping_sql_str = insert_transition_peptide_mapping_sql.str(); rc = sqlite3_exec(db, insert_transition_peptide_mapping_sql_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } // Execute SQL insert statement std::string insert_transition_precursor_mapping_sql_str = insert_transition_precursor_mapping_sql.str(); rc = sqlite3_exec(db, insert_transition_precursor_mapping_sql_str.c_str(), callback, 0, &zErrMsg); if ( rc != SQLITE_OK ) { sqlite3_free(zErrMsg); throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, zErrMsg); } sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &zErrMsg); sqlite3_close(db); }
void MainWindow::newDB() { this->setEnabled(false); // Save changes before proceeding? bool cancelled = saveChangesBeforeProceeding(tr("New database"), true); if (cancelled) { this->setEnabled(true); return; } // Creating database ------------------------------------------------------- bool ok; QString db_name = QInputDialog::getText(this, tr("New database"), tr("Database name:"), QLineEdit::Normal, tr("Untitled database"), &ok); QString saveDBName; if (!ok) { this->setEnabled(true); return; } if (!db_name.isEmpty()) { saveDBName = QFileDialog::getSaveFileName(this, tr("Create database file"), tr("%1.itdb").arg(db_name), tr("iTest databases (*.itdb)")); } else { saveDBName = QFileDialog::getSaveFileName(this, tr("Create database file"), tr("untitled.itdb"), tr("iTest databases (*.itdb)")); } if (saveDBName.isNull() || saveDBName.isEmpty()) { this->setEnabled(true); return; } QFile file(saveDBName); if (!file.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::critical(this, tr("Create database file"), tr("Cannot write file %1:\n%2.").arg(saveDBName).arg(file.errorString())); this->setWindowTitle(tr("iTestServer")); this->setEnabled(true); return; } bool itdb1_3 = saveDBName.endsWith(".it13.itdb"); clearAll(); setProgress(10); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> QTextStream sfile(&file); sfile.setCodec("UTF-8"); sfile << "[ITEST_VERSION]\n" << F_ITEST_VERSION << endl; sfile << "[ITEST_DB_VERSION]\n" << (itdb1_3 ? 1.3 : F_ITDB_VERSION) << endl; sfile << "[DB_NAME]\n" << db_name << endl; sfile << "[DB_DATE]\n" << endl; sfile << "[DB_DATE_ULSD]\ntrue" << endl; sfile << "[DB_COMMENTS]\n" << endl; sfile << "[DB_QNUM]\n0" << endl; sfile << "[DB_SNUM]\n0" << endl; if (!itdb1_3) sfile << "[DB_CNUM]\n0" << endl; sfile << "[DB_FLAGS]" << endl; sfile << "--------------------\n"; for (int i = 0; i < current_db_categories.size(); ++i) { sfile << "[DB_F" << i << "]\n" << endl; } sfile << "[DB_FLAGS_END]"; setProgress(50); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // APPLY setAllEnabled(true); current_db_file = saveDBName; current_db_open = true; addRecent(saveDBName); #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("Ready"), 10000); setProgress(100); setProgress(-1); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>> actionEdit_questions->setChecked(true); setPage(actionEdit_questions); this->setEnabled(true); // ------------------------------------------------------------------------- }
void Widget::update() { /// 1. Find and parse the update (0-5%) // Check that the dir exists QString updateDirStr = settings.getSettingsDirPath()+"/update/"; QDir updateDir(updateDirStr); if (!updateDir.exists()) fatalError(tr("No update found.")); setProgress(2); // Check that we have a flist and that every file on the diff exists QFile updateFlistFile(updateDirStr+"flist"); if (!updateFlistFile.open(QIODevice::ReadOnly)) fatalError(tr("The update is incomplete!")); QByteArray updateFlistData = updateFlistFile.readAll(); updateFlistFile.close(); QList<UpdateFileMeta> updateFlist = parseFlist(updateFlistData); setProgress(5); /// 2. Generate a diff (5-50%) QList<UpdateFileMeta> diff = genUpdateDiff(updateFlist, this); for (UpdateFileMeta fileMeta : diff) if (!QFile::exists(updateDirStr+fileMeta.installpath)) fatalError(tr("The update is incomplete.")); if (diff.size() == 0) fatalError(tr("The update is empty!")); setProgress(50); qDebug() << "Diff generated,"<<diff.size()<<"files to update"; /// 2. Check the update (50-75%) float checkProgressStep = 25.0/(float)diff.size(); float checkProgress = 50; for (UpdateFileMeta fileMeta : diff) { UpdateFile file; file.metadata = fileMeta; QFile fileFile(updateDirStr+fileMeta.installpath); if (!fileFile.open(QIODevice::ReadOnly)) fatalError(tr("Update files are unreadable.")); file.data = fileFile.readAll(); fileFile.close(); if (file.data.size() != (int)fileMeta.size) fatalError(tr("Update files are corrupted.")); if (crypto_sign_verify_detached(file.metadata.sig, (unsigned char*)file.data.data(), file.data.size(), key) != 0) fatalError(tr("Update files are corrupted.")); checkProgress += checkProgressStep; setProgress(checkProgress); } setProgress(75); qDebug() << "Update files signature verified, installing"; /// 3. Install the update (75-95%) float installProgressStep = 20.0/(float)diff.size(); float installProgress = 75; for (UpdateFileMeta fileMeta : diff) { // Backup old files if (QFile(fileMeta.installpath).exists()) { QFile(fileMeta.installpath+".bak").remove(); QFile(fileMeta.installpath).rename(fileMeta.installpath+".bak"); backups.append(fileMeta.installpath); } // Install new ones QDir().mkpath(QFileInfo(fileMeta.installpath).absolutePath()); QFile fileFile(updateDirStr+fileMeta.installpath); if (!fileFile.copy(fileMeta.installpath)) fatalError(tr("Unable to copy the update's files from ")+(updateDirStr+fileMeta.installpath)+" to "+fileMeta.installpath); installProgress += installProgressStep; setProgress(installProgress); } setProgress(95); /// 4. Delete the update and backups (95-100%) deleteUpdate(); setProgress(97); deleteBackups(); setProgress(100); /// 5. Start qTox and exit qDebug() << "Update applied, restarting qTox!"; startQToxAndExit(); }
//data loading bool ModelData::LoadIn(QString filepath) { bool loaderReady; bool abort; STLTri* pLoadedTri = NULL; Triangle3D newtri; this->filepath = filepath; if(filepath.isEmpty()) return false; //extract filename from path! filename = QFileInfo(filepath).fileName(); B9ModelLoader mLoader(filepath,loaderReady,NULL); if(loaderReady == false)//error opening model data { //display Loader Error QMessageBox msgBox; msgBox.setText(mLoader.GetError()); msgBox.exec(); return false; } //make a progress bar and connect it to LoadingBar loadbar(0,100); loadbar.useCancelButton(false); loadbar.setDescription("Importing: " + filename); QObject::connect(&mLoader,SIGNAL(PercentCompletedUpdate(qint64,qint64)), &loadbar,SLOT(setProgress(qint64,qint64))); //now we are ready to walk the loader through reading each triangle //and copying it into the this model data. while(mLoader.LoadNextTri(pLoadedTri,abort)) { if(abort) { //display Loader abort error QMessageBox msgBox; msgBox.setText(mLoader.GetError()); msgBox.exec(); return false; } else { //newtri.normal.setX(pLoadedTri->nx); //newtri.normal.setY(pLoadedTri->ny); //newtri.normal.setZ(pLoadedTri->nz); newtri.vertex[0].setX(pLoadedTri->x0); newtri.vertex[0].setY(pLoadedTri->y0); newtri.vertex[0].setZ(pLoadedTri->z0); newtri.vertex[1].setX(pLoadedTri->x1); newtri.vertex[1].setY(pLoadedTri->y1); newtri.vertex[1].setZ(pLoadedTri->z1); newtri.vertex[2].setX(pLoadedTri->x2); newtri.vertex[2].setY(pLoadedTri->y2); newtri.vertex[2].setZ(pLoadedTri->z2); //use right hand rule for importing normals - ignore file normals.. newtri.UpdateNormalFromGeom(); delete pLoadedTri; newtri.UpdateBounds(); triList.push_back(newtri); } } qDebug() << "Loaded triangles: " << triList.size(); //now center it! CenterModel(); //generate a normal display lists. int displaySuccess = FormNormalDisplayLists(); if(displaySuccess) return true; else return false; }
unsigned int ProgressMonitor::operator += (unsigned int increment) { setProgress(_progress + increment); return _progress; }
void KxProgressIndicator::finish() { fIsInUse = false; setProgress(minValue()); setIsInterruptable(false); }
void StatusBar::setProgress(int steps) { setProgress(sender(), steps); }
QImage PosterizeFilter::apply(const QImage& image, const QRect& clipRect) { QMutexLocker locker(&m_mutex); if (m_lut.isEmpty()) { updateLut(); } QImage resultImg = image.convertToFormat(QImage::Format_ARGB32); QRect rc = clipRect; if (rc.isEmpty()) { rc = image.rect(); } m_isAborting = false; for (int y = rc.y(); y <= rc.bottom(); ++y) { if (m_isAborting) { return QImage(); } QRgb* line = reinterpret_cast<QRgb*>(resultImg.scanLine(y)); switch (m_mode) { case PosterizeFilter::RGB: for (int x = rc.x(); x <= rc.right(); ++x) { line[x] = qRgb(m_lut[qRed(line[x])], m_lut[qGreen(line[x])], m_lut[qBlue(line[x])]); } break; case PosterizeFilter::HSV: for (int x = rc.x(); x <= rc.right(); ++x) { QColor c(line[x]); int h, s, v; c.getHsv(&h, &s, &v); if (h < 0) h = 0; h = m_lut[h]; c.setHsv(h,s,v); line[x] = c.rgba(); } break; case PosterizeFilter::CHROMA: case PosterizeFilter::LUMA: for (int x = rc.x(); x <= rc.right(); ++x) { int y, u, v; ColorConversions::rgbToYuv(line[x], &y, &u, &v); if (m_mode == PosterizeFilter::CHROMA) { y = m_lut[y]; } else { u = m_lut[u]; v = m_lut[v]; } line[x] = ColorConversions::yuvToRgb(y, u, v); } }; setProgress(int((y - rc.y()) * 100.0 / rc.height())); } return resultImg; }
void SingleLinkage::operator()(DistanceMatrix<float> & original_distance, std::vector<BinaryTreeNode> & cluster_tree, const float threshold /*=1*/) const { // input MUST have >= 2 elements! if (original_distance.dimensionsize() < 2) { throw ClusterFunctor::InsufficientInput(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Distance matrix to start from only contains one element"); } cluster_tree.clear(); if (threshold < 1) { LOG_ERROR << "You tried to use Single Linkage clustering with a threshold. This is currently not supported!" << std::endl; throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION); } //SLINK std::vector<Size> pi; pi.reserve(original_distance.dimensionsize()); std::vector<float> lambda; lambda.reserve(original_distance.dimensionsize()); startProgress(0, original_distance.dimensionsize(), "clustering data"); //initialize first pointer values pi.push_back(0); lambda.push_back(std::numeric_limits<float>::max()); for (Size k = 1; k < original_distance.dimensionsize(); ++k) { std::vector<float> row_k; row_k.reserve(k); //initialize pointer values for element to cluster pi.push_back(k); lambda.push_back(std::numeric_limits<float>::max()); // get the right distances for (Size i = 0; i < k; ++i) { row_k.push_back(original_distance.getValue(i, k)); } //calculate pointer values for element k for (Size i = 0; i < k; ++i) { if (lambda[i] >= row_k[i]) { row_k[pi[i]] = std::min(row_k[pi[i]], lambda[i]); lambda[i] = row_k[i]; pi[i] = k; } else { row_k[pi[i]] = std::min(row_k[pi[i]], row_k[i]); } } //update clustering if necessary for (Size i = 0; i < k; ++i) { if (lambda[i] >= lambda[pi[i]]) { pi[i] = k; } } setProgress(k); } for (Size i = 0; i < pi.size() - 1; ++i) { //strict order is always kept in algorithm: i < pi[i] cluster_tree.push_back(BinaryTreeNode(i, pi[i], lambda[i])); //~ std::cout << i << '\n' << pi[i] << '\n' << lambda[i] << std::endl; } //sort pre-tree std::sort(cluster_tree.begin(), cluster_tree.end(), compareBinaryTreeNode); // convert -pre-tree to correct format for (Size i = 0; i < cluster_tree.size(); ++i) { if (cluster_tree[i].right_child < cluster_tree[i].left_child) { std::swap(cluster_tree[i].left_child, cluster_tree[i].right_child); } for (Size k = i + 1; k < cluster_tree.size(); ++k) { if (cluster_tree[k].left_child == cluster_tree[i].right_child) { cluster_tree[k].left_child = cluster_tree[i].left_child; } else if (cluster_tree[k].left_child > cluster_tree[i].right_child) { --cluster_tree[k].left_child; } if (cluster_tree[k].right_child == cluster_tree[i].right_child) { cluster_tree[k].right_child = cluster_tree[i].left_child; } else if (cluster_tree[k].right_child > cluster_tree[i].right_child) { --cluster_tree[k].right_child; } } } //~ prepare to redo clustering to get all indices for binarytree in min index element representation std::vector<std::set<Size> > clusters(original_distance.dimensionsize()); for (Size i = 0; i < original_distance.dimensionsize(); ++i) { clusters[i].insert(i); } for (Size cluster_step = 0; cluster_step < cluster_tree.size(); ++cluster_step) { Size new_left_child = *(clusters[cluster_tree[cluster_step].left_child].begin()); Size new_right_child = *(clusters[cluster_tree[cluster_step].right_child].begin()); clusters[cluster_tree[cluster_step].left_child].insert(clusters[cluster_tree[cluster_step].right_child].begin(), clusters[cluster_tree[cluster_step].right_child].end()); clusters.erase(clusters.begin() + cluster_tree[cluster_step].right_child); std::swap(cluster_tree[cluster_step].left_child, new_left_child); std::swap(cluster_tree[cluster_step].right_child, new_right_child); if (cluster_tree[cluster_step].left_child > cluster_tree[cluster_step].right_child) { std::swap(cluster_tree[cluster_step].left_child, cluster_tree[cluster_step].right_child); } } endProgress(); }
void MPHFAlgorithm<span,Abundance_t,NodeState_t>::populate () { size_t nb_iterated = 0; size_t n = _abundanceMap->size(); _nb_abundances_above_precision = 0; /** We need a progress object. */ tools::dp::IteratorListener* delegate = createIteratorListener(_solidCounts->getNbItems(),messages[3]); LOCAL (delegate); setProgress (new ProgressCustom(delegate)); SubjectIterator<Count>* itKmers = new SubjectIterator<Count> (_solidCounts->iterator(), _solidCounts->getNbItems()/100); itKmers->addObserver (_progress); LOCAL (itKmers); // TODO parallize that std::vector<int> & _abundanceDiscretization = _abundanceMap->_abundanceDiscretization ; int max_abundance_discrete = _abundanceDiscretization[_abundanceDiscretization.size()-2]; // set counts and at the same time, test the mphf for (itKmers->first(); !itKmers->isDone(); itKmers->next()) { //cout << "kmer: " << itKmers->item().value.toString(21) << std::endl; /** We get the hash code of the current item. */ typename AbundanceMap::Hash::Code h = _abundanceMap->getCode (itKmers->item().value); /** Little check. */ if (h >= n) { throw Exception ("MPHF check: value out of bounds"); } /** We get the abundance of the current kmer. */ int abundance = itKmers->item().abundance; if (abundance > max_abundance_discrete) { _nb_abundances_above_precision++; abundance = max_abundance_discrete; } //get first cell strictly greater than abundance std::vector<int>::iterator up = std::upper_bound(_abundanceDiscretization.begin(), _abundanceDiscretization.end(), abundance); up--; // get previous cell int idx = up- _abundanceDiscretization.begin() ; /** We set the abundance of the current kmer. */ _abundanceMap->at (h) = idx; nb_iterated ++; } if (nb_iterated != n && n > 3) { throw Exception ("ERROR during abundance population: itKmers iterated over %d/%d kmers only", nb_iterated, n); } #if 1 // you know what? let's always test if the MPHF does not have collisions, it won't hurt. check (); #endif /** We gather some statistics. */ getInfo()->add (1, "stats"); getInfo()->add (2, "nb_keys", "%ld", _abundanceMap->size()); getInfo()->add (2, "data_size", "%ld", _dataSize); getInfo()->add (2, "bits_per_key", "%.3f", (float)(_dataSize*8)/(float)_abundanceMap->size()); getInfo()->add (2, "prec", "%d", MAX_ABUNDANCE); getInfo()->add (2, "nb_abund_above_prec", "%d", _nb_abundances_above_precision); getInfo()->add (1, getTimeInfo().getProperties("time")); }
void reportProgress (double progress) { setProgress (progress); };
NPlayer::NPlayer() { qsrand((uint)QTime::currentTime().msec()); m_settings = NSettings::instance(); NI18NLoader::init(); m_playbackEngine = dynamic_cast<NPlaybackEngineInterface *>(NPluginLoader::getPlugin(N::PlaybackEngine)); m_playbackEngine->setParent(this); #ifndef _N_NO_SKINS_ m_mainWindow = new NMainWindow(NSkinLoader::skinUiFormFile()); #else m_mainWindow = new NMainWindow(); #endif // loading skin script m_scriptEngine = new NScriptEngine(this); #ifndef _N_NO_SKINS_ QString scriptFileName(NSkinLoader::skinScriptFile()); #else QString scriptFileName(":skins/native/script.js"); #endif QFile scriptFile(scriptFileName); scriptFile.open(QIODevice::ReadOnly); m_scriptEngine->evaluate(scriptFile.readAll(), scriptFileName); scriptFile.close(); QScriptValue skinProgram = m_scriptEngine->evaluate("Main").construct(); m_aboutDialog = NULL; m_logDialog = new NLogDialog(m_mainWindow); m_preferencesDialog = new NPreferencesDialog(m_mainWindow); m_volumeSlider = qFindChild<NVolumeSlider *>(m_mainWindow, "volumeSlider"); m_coverWidget = qFindChild<QWidget *>(m_mainWindow, "coverWidget"); m_playlistWidget = qFindChild<NPlaylistWidget *>(m_mainWindow, "playlistWidget"); if (QAbstractButton *repeatButton = qFindChild<QAbstractButton *>(m_mainWindow, "repeatButton")) repeatButton->setChecked(m_playlistWidget->repeatMode()); m_trackInfoWidget = new NTrackInfoWidget(); QVBoxLayout *trackInfoLayout = new QVBoxLayout; trackInfoLayout->setContentsMargins(0, 0, 0, 0); trackInfoLayout->addWidget(m_trackInfoWidget); m_waveformSlider = qFindChild<NWaveformSlider *>(m_mainWindow, "waveformSlider"); m_waveformSlider->setLayout(trackInfoLayout); #ifndef _N_NO_UPDATE_CHECK_ m_versionDownloader = new QNetworkAccessManager(this); connect(m_versionDownloader, SIGNAL(finished(QNetworkReply *)), this, SLOT(on_versionDownloader_finished(QNetworkReply *))); connect(m_preferencesDialog, SIGNAL(versionRequested()), this, SLOT(downloadVersion())); #endif createActions(); loadSettings(); connectSignals(); #ifdef Q_WS_WIN NW7TaskBar::instance()->setWindow(m_mainWindow); NW7TaskBar::instance()->setEnabled(NSettings::instance()->value("TaskbarProgress").toBool()); connect(m_playbackEngine, SIGNAL(positionChanged(qreal)), NW7TaskBar::instance(), SLOT(setProgress(qreal))); #endif #ifdef Q_WS_MAC NMacDock::instance()->registerClickHandler(); connect(NMacDock::instance(), SIGNAL(clicked()), m_mainWindow, SLOT(show())); #endif m_mainWindow->setTitle(QCoreApplication::applicationName() + " " + QCoreApplication::applicationVersion()); m_mainWindow->show(); m_mainWindow->loadSettings(); QResizeEvent e(m_mainWindow->size(), m_mainWindow->size()); QCoreApplication::sendEvent(m_mainWindow, &e); skinProgram.property("afterShow").call(skinProgram); }
void QFListProgressDialog::setValue(int value) { setProgress(value); }
void QProgressBar::setProgress( int progress, int totalSteps ) { if ( total_steps != totalSteps ) setTotalSteps( totalSteps ); setProgress( progress ); }
void MainWindow::resetProgress() { setProgress(0); setRuntime(""); }
KProgress::KProgress(QWidget *parent, const char *name, WFlags f) : QProgressBar(parent, name, f), mFormat("%p%") { setProgress(0); }