bool RunsTableModel::postRow(int row_no, bool throw_exc) { bool is_single_user = sqlConnection().driverName().endsWith(QLatin1String("SQLITE"), Qt::CaseInsensitive); if(is_single_user) return Super::postRow(row_no, throw_exc); int col_stime = columnIndex("startTimeMs"); QF_ASSERT(col_stime >= 0, "Bad startTimeMs column!", return false); if(isDirty(row_no, col_stime)) { int id = value(row_no, "runs.id").toInt(); int orig_msec = origValue(row_no, col_stime).toInt(); int db_msec = 0; qf::core::sql::Transaction transaction(sqlConnection()); QString qs = "SELECT id, startTimeMs FROM runs WHERE id=" QF_IARG(id) " FOR UPDATE"; qf::core::sql::Query q(transaction.connection()); q.exec(qs, qf::core::Exception::Throw); if(q.next()) { db_msec = q.value("startTimeMs").toInt(); } if(orig_msec == db_msec) { bool ret = Super::postRow(row_no, throw_exc); transaction.commit(); return ret; } else { QString err_msg = tr("Mid-air collision setting start time, reload table and try it again."); revertRow(row_no); if(throw_exc) QF_EXCEPTION(err_msg); return false; } } return Super::postRow(row_no, throw_exc); }
bool RunsTableModel::setValue(int row_ix, int column_ix, const QVariant &val) { bool ret; ColumnDefinition cd = columnDefinition(column_ix); if(cd.matchesSqlId(QStringLiteral("finishTimeMs"))) { QVariant start_ms = value(row_ix, "startTimeMs"); if(!start_ms.isNull()) { int time_ms = val.toInt() - start_ms.toInt(); if(time_ms > 0) { Super::setValue(row_ix, "timeMs", time_ms); } } } else if(cd.matchesSqlId(QStringLiteral("timeMs"))) { QVariant start_ms = value(row_ix, "startTimeMs"); if(!start_ms.isNull()) { int finish_ms = val.toInt() + start_ms.toInt(); if(finish_ms > 0) { Super::setValue(row_ix, columnIndex("finishTimeMs"), finish_ms); } } } else if(cd.matchesSqlId(QStringLiteral("startTimeMs"))) { if(!val.isNull()) { int start_ms = val.toInt(); int finish_ms = value(row_ix, "finishTimeMs").toInt(); int time_ms = value(row_ix, "timeMs").toInt(); if(finish_ms > 0) { int time_ms = finish_ms - start_ms; Super::setValue(row_ix, columnIndex("timeMs"), time_ms); } else if(time_ms > 0) { finish_ms = start_ms + time_ms; Super::setValue(row_ix, "finishTimeMs", finish_ms); } } } ret = Super::setValue(row_ix, column_ix, val); return ret; }
// This returns a matrix that is the lower-triangular part (only column // index <= row index) of the square of matrixToSquare. Eigen::MatrixXcd SymmetricComplexMassMatrix::LowerTriangleOfSquareMatrix( Eigen::MatrixXcd const& matrixToSquare ) const { Eigen::MatrixXcd valuesSquaredMatrix( numberOfRows, numberOfRows ); for( size_t rowIndex( 0 ); rowIndex < numberOfRows; ++rowIndex ) { for( size_t columnIndex( 0 ); columnIndex <= rowIndex; ++columnIndex ) { valuesSquaredMatrix.coeffRef( rowIndex, columnIndex ).real(0.0); valuesSquaredMatrix.coeffRef( rowIndex, columnIndex ).imag(0.0); for( size_t sumIndex( 0 ); sumIndex < numberOfRows; ++sumIndex ) { double temp = valuesSquaredMatrix.coeffRef( rowIndex, columnIndex ).real() + ( ( matrixToSquare.coeff( sumIndex, rowIndex ).real() * matrixToSquare.coeff( sumIndex, columnIndex ).real() ) + ( matrixToSquare.coeff( sumIndex, rowIndex ).imag() * matrixToSquare.coeff( sumIndex, columnIndex ).imag() ) ); valuesSquaredMatrix.coeffRef( rowIndex, columnIndex ).real(temp); temp = valuesSquaredMatrix.coeffRef( rowIndex, columnIndex ).imag() + ( ( matrixToSquare.coeff( sumIndex, rowIndex ).real() * matrixToSquare.coeff( sumIndex, columnIndex ).imag() ) - ( matrixToSquare.coeff( sumIndex, rowIndex ).imag() * matrixToSquare.coeff( sumIndex, columnIndex ).real() ) ); valuesSquaredMatrix.coeffRef( rowIndex, columnIndex ).imag(temp); // The Eigen routines don't bother looking at elements of // valuesSquaredMatrix where columnIndex > rowIndex, so we don't even // bother filling them with the conjugates of the transpose. } } } return valuesSquaredMatrix; }
QVariant EventStatisticsModel::data(const QModelIndex &index, int role) const { int col = index.column(); static int col_free_map_count = columnIndex(QStringLiteral("freeMapCount")); if(role == Qt::BackgroundRole) { if(col == col_free_map_count) { int cnt = data(index, Qt::DisplayRole).toInt(); if(cnt < 0) return QColor(Qt::red); return QVariant(); } } return Super::data(index, role); }
void RunsTableModel::switchStartTimes(int r1, int r2) { qfLogFuncFrame() << r1 << r2; int col_stime = columnIndex("startTimeMs"); QF_ASSERT(col_stime >= 0, "Bad startTimeMs column!", return); int id1 = value(r1, "runs.id").toInt(); int id2 = value(r2, "runs.id").toInt(); QString err_msg; QModelIndex ix1 = index(r1, col_stime); QVariant v1 = ix1.data(Qt::EditRole); QModelIndex ix2 = index(r2, col_stime); QVariant v2 = ix2.data(Qt::EditRole); bool is_single_user = sqlConnection().driverName().endsWith(QLatin1String("SQLITE"), Qt::CaseInsensitive); if(is_single_user) { setData(ix1, v2); setData(ix2, v1); postRow(r1, true); postRow(r2, true); } else { //qf::core::sql::Transaction transaction(sqlConnection()); quickevent::core::og::TimeMs t1 = v1.value<quickevent::core::og::TimeMs>(); quickevent::core::og::TimeMs t2 = v2.value<quickevent::core::og::TimeMs>(); int msec1 = -1, msec2 = -1; qf::core::sql::Query q(sqlConnection()); QString qs = "SELECT id, startTimeMs FROM runs WHERE id IN (" QF_IARG(id1) ", " QF_IARG(id2) ")"; q.exec(qs, qf::core::Exception::Throw); while(q.next()) { int id = q.value("id").toInt(); if(id == id1) msec1 = q.value("startTimeMs").toInt(); else if(id == id2) msec2 = q.value("startTimeMs").toInt(); } qfDebug() << t1.msec() << msec1 << t2.msec() << msec2; if(msec1 == t1.msec() && msec2 == t2.msec()) { setData(ix1, v2); setData(ix2, v1); postRow(r1, qf::core::Exception::Throw); postRow(r2, qf::core::Exception::Throw); //transaction.commit(); } else { err_msg = tr("Mid-air collision switching start times, reload table and try it again."); } } emit startTimesSwitched(id1, id2, err_msg); }
autoConfusion Confusion_condense (Confusion me, const char32 *search, const char32 *replace, long maximumNumberOfReplaces, int use_regexp) { try { long nmatches, nstringmatches; if (my rowLabels == 0 || my columnLabels == 0) { Melder_throw (U"No row or column labels."); } autostring32vector rowLabels (strs_replace (my rowLabels, 1, my numberOfRows, search, replace, maximumNumberOfReplaces, &nmatches, &nstringmatches, use_regexp), 1, my numberOfRows); autostring32vector columnLabels (strs_replace (my columnLabels, 1, my numberOfColumns, search, replace, maximumNumberOfReplaces, &nmatches, &nstringmatches, use_regexp), 1, my numberOfColumns); autoStrings srow = Thing_new (Strings); srow -> numberOfStrings = my numberOfRows; srow -> strings = rowLabels.transfer(); autoStrings scol = Thing_new (Strings); scol -> numberOfStrings = my numberOfColumns; scol -> strings = columnLabels.transfer(); /* Find dimension of new Confusion */ autoDistributions dcol = Strings_to_Distributions (scol.get()); long nresp = dcol -> numberOfRows; autoDistributions drow = Strings_to_Distributions (srow.get()); long nstim = drow -> numberOfRows; autoConfusion thee = Confusion_create (nstim, nresp); NUMstrings_copyElements (drow -> rowLabels, thy rowLabels, 1, nstim); NUMstrings_copyElements (dcol -> rowLabels, thy columnLabels, 1, nresp); autoNUMvector<long> rowIndex (1, my numberOfRows); create_index (srow -> strings, 1, my numberOfRows, drow -> rowLabels, 1, nstim, rowIndex.peek()); autoNUMvector<long> columnIndex (1, my numberOfColumns); create_index (scol -> strings, 1, my numberOfColumns, dcol -> rowLabels, 1, nresp, columnIndex.peek()); for (long i = 1; i <= my numberOfRows; i++) { for (long j = 1; j <= my numberOfColumns; j++) { thy data [rowIndex [i]][columnIndex[j]] += my data[i][j]; } } return thee; } catch (MelderError) { Melder_throw (me, U": not condensed."); } }
// This returns a matrix of the values of the elements for a field // configuration given by fieldConfiguration, using the values for the // Lagrangian parameters found in parameterValues. Eigen::MatrixXcd SymmetricComplexMassMatrix::MatrixToSquare( std::vector< double > const& parameterValues, std::vector< double > const& fieldConfiguration ) const { size_t rowsTimesLength( 0 ); Eigen::MatrixXcd valuesMatrix( numberOfRows, numberOfRows ); for( size_t rowIndex( 0 ); rowIndex < numberOfRows; ++rowIndex ) { for( size_t columnIndex( 0 ); columnIndex < rowIndex; ++columnIndex ) { valuesMatrix.coeffRef( rowIndex, columnIndex ).real(matrixElements[ rowsTimesLength + columnIndex ].first( parameterValues, fieldConfiguration )); valuesMatrix.coeffRef( rowIndex, columnIndex ).imag(matrixElements[ rowsTimesLength + columnIndex ].second( parameterValues, fieldConfiguration )); // We use the fact that the matrix is symmetric. valuesMatrix.coeffRef( columnIndex, rowIndex ) = valuesMatrix.coeff( rowIndex, columnIndex ); } valuesMatrix.coeffRef( rowIndex, rowIndex ).real(matrixElements[ rowsTimesLength + rowIndex ].first( parameterValues, fieldConfiguration )); valuesMatrix.coeffRef( rowIndex, rowIndex ).imag(matrixElements[ rowsTimesLength + rowIndex ].second( parameterValues, fieldConfiguration )); rowsTimesLength += numberOfRows; } return valuesMatrix; }
QVariant EventStatisticsModel::value(int row_ix, int column_ix) const { static int col_map_count = columnIndex(QStringLiteral("classdefs.mapCount")); static int col_free_map_count = columnIndex(QStringLiteral("freeMapCount")); static int col_runners_count = columnIndex(QStringLiteral("runnersCount")); static int col_runners_finished = columnIndex(QStringLiteral("runnersFinished")); static int col_runners_not_finished = columnIndex(QStringLiteral("runnersNotFinished")); static int col_results_not_printed = columnIndex(QStringLiteral("resultsNotPrinted")); if(column_ix == col_free_map_count) { int cnt = value(row_ix, col_map_count).toInt() - value(row_ix, col_runners_count).toInt(); return cnt; } else if(column_ix == col_runners_not_finished) { int cnt = value(row_ix, col_runners_count).toInt() - value(row_ix, col_runners_finished).toInt(); return cnt; } else if(column_ix == col_results_not_printed) { int results_count = tableRow(row_ix).value(QStringLiteral("resultsCount")).toInt(); int cnt = value(row_ix, col_runners_finished).toInt() - results_count; return cnt; } return Super::value(row_ix, column_ix); }
void XTreeView::setColumnRole(const QString column, int role, const QVariant value) { _model->setColumnRole(columnIndex(column), role, value); }
void XTableView::setItemDelegateForColumn(const QString column, QAbstractItemDelegate * delegate) { setItemDelegateForColumn(columnIndex(column), delegate); }
QAbstractItemDelegate* XTableView::itemDelegateForColumn(const QString column) { return itemDelegateForColumn(columnIndex(column)); }