void ItemModel::insert(const Item &item, int index) { beginInsertRows(QModelIndex(), index, 0); m_items.insert(index, item); endInsertRows(); }
void PlaylistModel::endInsertItems() { endInsertRows(); }
void DescriptionModel::descriptionAdded(const QString &description) { Q_UNUSED(description) endInsertRows(); }
int DivePlannerPointsModel::addStop(int milimeters, int seconds, int cylinderid_in, int ccpoint, bool entered) { int cylinderid = 0; bool usePrevious = false; if (cylinderid_in) cylinderid = cylinderid_in; else usePrevious = true; if (recalcQ()) removeDeco(); int row = divepoints.count(); if (seconds == 0 && milimeters == 0 && row != 0) { /* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */ const divedatapoint t = divepoints.at(lastEnteredPoint()); milimeters = t.depth; seconds = t.time + 600; // 10 minutes. cylinderid = t.cylinderid; ccpoint = t.setpoint; } else if (seconds == 0 && milimeters == 0 && row == 0) { milimeters = M_OR_FT(5, 15); // 5m / 15ft seconds = 600; // 10 min // Default to the first cylinder cylinderid = 0; } // check if there's already a new stop before this one: for (int i = 0; i < row; i++) { const divedatapoint &dp = divepoints.at(i); if (dp.time == seconds) { row = i; beginRemoveRows(QModelIndex(), row, row); divepoints.remove(row); endRemoveRows(); break; } if (dp.time > seconds) { row = i; break; } } // Previous, actually means next as we are typically subdiving a segment and the gas for // the segment is determined by the waypoint at the end. if (usePrevious) { if (row < divepoints.count()) { cylinderid = divepoints.at(row).cylinderid; } else if (row > 0) { cylinderid = divepoints.at(row - 1).cylinderid; } } // add the new stop beginInsertRows(QModelIndex(), row, row); divedatapoint point; point.depth = milimeters; point.time = seconds; point.cylinderid = cylinderid; point.setpoint = ccpoint; point.entered = entered; point.next = NULL; divepoints.append(point); std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan); endInsertRows(); return row; }
bool UdpListModel::insertRow(int row, const QModelIndex &parent) { beginInsertRows(parent, row, row + 1); endInsertRows(); return true; }
void append(const Vehicle & vehicle) { beginInsertRows({}, m_data.count(), m_data.count()); m_data.append(vehicle); endInsertRows(); }
void DiveListModel::addDive(dive *d) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); m_dives.append(MobileDive(d)); endInsertRows(); }
// actually add to table in GUI void RecentRequestsTableModel::addNewRequest(RecentRequestEntry &recipient) { beginInsertRows(QModelIndex(), 0, 0); list.prepend(recipient); endInsertRows(); }
void PgnDatabaseModel::onDatabaseAdded(int index) { beginInsertRows(QModelIndex(), index, index); endInsertRows(); }
void PluginModel::addPlugin(PluginInterface *plugin) { beginInsertRows(QModelIndex(), m_plugins.count(), m_plugins.count()); m_plugins.append(plugin); endInsertRows(); }
LogMonitorFileModel::LogMonitorFileModel(const QString &dbPath, QObject *parent) :AbstractLogModel(parent) { m_statistics.error = 0; m_statistics.warning = 0; m_statistics.notice = 0; m_statistics.info = 0; m_statistics.clients = 0; QFile f(dbPath); if (!f.exists()) { QMessageBox msg; msg.setIcon(QMessageBox::Warning); msg.setText("File not found"); msg.setInformativeText(QString("Could not find file %1").arg(dbPath)); msg.exec(); return; } QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(dbPath); auto success = db.open(); if (!success) { auto e = db.lastError(); QMessageBox msg; msg.setIcon(QMessageBox::Warning); msg.setText("Open failed"); msg.setInformativeText(QString("Failed to open the file %1.\nError message: %2").arg(dbPath, e.text())); msg.exec(); return; } QSqlQuery query("SELECT m.time, m.pid, m.level, h.name, c.facility, c.object, m.message, p.process" " FROM messages AS m INNER JOIN hosts AS h ON m.host=h.id INNER JOIN channels AS c ON m.channel=c.id INNER JOIN processes AS p ON m.pid=p.id", db); query.setForwardOnly(true); success = query.exec(); if (!success) { auto e = db.lastError(); QMessageBox msg; msg.setIcon(QMessageBox::Warning); msg.setText("Open failed"); msg.setInformativeText(QString("Failed to open the file %1.\nError message: %2").arg(dbPath, e.text())); msg.exec(); return; } while (query.next()) { auto message = new LogMessage; message->timestamp.setMSecsSinceEpoch(qint64(query.value(0).toDouble() * 1000)); message->pid = query.value(1).toULongLong(); message->severity = LogSeverity(query.value(2).toInt()); message->machineName = query.value(3).toString(); message->module = query.value(4).toString(); message->channel = query.value(5).toString(); message->message = query.value(6).toString(); message->executablePath = query.value(7).toString(); switch (message->severity) { case SEVERITY_ERR: m_statistics.error++; break; case SEVERITY_WARN: m_statistics.warning++; break; case SEVERITY_NOTICE: m_statistics.notice++; break; case SEVERITY_INFO: m_statistics.info++; break; default: break; } addMessage(message); } if (m_messages.size()) { beginInsertRows(QModelIndex(), 0, m_messages.size() - 1); endInsertRows(); } db.close(); }
void InterfaceTreeCacheModel::addDevice(interface_t * newDevice) { emit beginInsertRows(QModelIndex(), rowCount(), rowCount()); newDevices << newDevice; emit endInsertRows(); }
void FavoriteTagsModel::appendTag(const ItemFavoriteTagItem &item) { beginInsertRows(QModelIndex(), m_tags.size(), m_tags.size()); m_tags << item; endInsertRows(); }
bool TutorModel::insertRows(int row, int count, const QModelIndex &parent) { beginInsertRows(QModelIndex(), row, row+count-1); endInsertRows(); return true; }
void TaskModelAdapter::taskAdded( TaskId id ) { endInsertRows(); }
bool CPlaylistModel::insertItem(CPlaylistItem* item, int pos) { beginInsertRows(QModelIndex(), pos, pos); m_playlistPtr->insertItem(item, pos); endInsertRows(); }
void ConsoleLineBuffer::createNewLine() { beginInsertRows(QModelIndex(), list_.count(), list_.count()); list_.append(ConsoleLine()); endInsertRows(); }
void SelectionModel::append(const QString &name, const QVariant &value) { beginInsertRows(QModelIndex(), m_items.size(), m_items.size()); m_items << QPair<QString, QVariant>(name, value); endInsertRows(); emit countChanged(rowCount()); }
void MergedProxyModel::RowsInserted(const QModelIndex&, int, int) { endInsertRows(); }
void PlayListModel::endInsertItems() { endInsertRows(); qDebug("endInsertItems"); }
bool ModList::installMod(const QFileInfo &filename, int index) { if (!filename.exists() || !filename.isReadable() || index < 0) { return false; } Mod m(filename); if (!m.valid()) return false; // if it's already there, replace the original mod (in place) int idx = mods.indexOf(m); if (idx != -1) { int idx2 = mods.indexOf(m,idx+1); if(idx2 != -1) return false; if (mods[idx].replace(m)) { auto left = this->index(index); auto right = this->index(index, columnCount(QModelIndex()) - 1); emit dataChanged(left, right); saveListFile(); emit changed(); return true; } return false; } auto type = m.type(); if (type == Mod::MOD_UNKNOWN) return false; if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD) { QString newpath = PathCombine(m_dir.path(), filename.fileName()); if (!QFile::copy(filename.filePath(), newpath)) return false; m.repath(newpath); beginInsertRows(QModelIndex(), index, index); mods.insert(index, m); endInsertRows(); saveListFile(); emit changed(); return true; } else if (type == Mod::MOD_FOLDER) { QString from = filename.filePath(); QString to = PathCombine(m_dir.path(), filename.fileName()); if (!copyPath(from, to)) return false; m.repath(to); beginInsertRows(QModelIndex(), index, index); mods.insert(index, m); endInsertRows(); saveListFile(); emit changed(); return true; } return false; }
void BaseSqlTableModel::select() { if (!m_bInitialized) { return; } // We should be able to detect when a select() would be a no-op. The DAO's // do not currently broadcast signals for when common things happen. In the // future, we can turn this check on and avoid a lot of needless // select()'s. rryan 9/2011 // if (!m_bDirty) { // if (sDebug) { // qDebug() << this << "Skipping non-dirty select()"; // } // return; // } if (sDebug) { qDebug() << this << "select()"; } PerformanceTimer time; time.start(); // Prepare query for id and all columns not in m_trackSource QString queryString = QString("SELECT %1 FROM %2 %3") .arg(m_tableColumnsJoined, m_tableName, m_tableOrderBy); if (sDebug) { qDebug() << this << "select() executing:" << queryString; } QSqlQuery query(m_database); // This causes a memory savings since QSqlCachedResult (what QtSQLite uses) // won't allocate a giant in-memory table that we won't use at all. query.setForwardOnly(true); query.prepare(queryString); if (!query.exec()) { LOG_FAILED_QUERY(query); return; } // Remove all the rows from the table. We wait to do this until after the // table query has succeeded. See Bug #1090888. // TODO(rryan) we could edit the table in place instead of clearing it? if (!m_rowInfo.isEmpty()) { beginRemoveRows(QModelIndex(), 0, m_rowInfo.size() - 1); m_rowInfo.clear(); m_trackIdToRows.clear(); endRemoveRows(); } // sqlite does not set size and m_rowInfo was just cleared //if (sDebug) { // qDebug() << "Rows returned" << rows << m_rowInfo.size(); //} QVector<RowInfo> rowInfo; QSet<TrackId> trackIds; while (query.next()) { TrackId trackId(query.value(kIdColumn)); trackIds.insert(trackId); RowInfo thisRowInfo; thisRowInfo.trackId = trackId; // save rows where this currently track id is located thisRowInfo.order = rowInfo.size(); // Get all the table columns and store them in the hash for this // row-info section. thisRowInfo.metadata.reserve(m_tableColumns.size()); for (int i = 0; i < m_tableColumns.size(); ++i) { thisRowInfo.metadata << query.value(i); } rowInfo.push_back(thisRowInfo); } if (sDebug) { qDebug() << "Rows actually received:" << rowInfo.size(); } if (m_trackSource) { m_trackSource->filterAndSort(trackIds, m_currentSearch, m_currentSearchFilter, m_trackSourceOrderBy, m_trackSourceSortColumn, m_trackSourceSortOrder, &m_trackSortOrder); // Re-sort the track IDs since filterAndSort can change their order or mark // them for removal (by setting their row to -1). for (QVector<RowInfo>::iterator it = rowInfo.begin(); it != rowInfo.end(); ++it) { // If the sort is not a track column then we will sort only to // separate removed tracks (order == -1) from present tracks (order == // 0). Otherwise we sort by the order that filterAndSort returned to us. if (m_trackSourceOrderBy.isEmpty()) { it->order = m_trackSortOrder.contains(it->trackId) ? 0 : -1; } else { it->order = m_trackSortOrder.value(it->trackId, -1); } } } // RowInfo::operator< sorts by the order field, except -1 is placed at the // end so we can easily slice off rows that are no longer present. Stable // sort is necessary because the tracks may be in pre-sorted order so we // should not disturb that if we are only removing tracks. qStableSort(rowInfo.begin(), rowInfo.end()); m_trackIdToRows.clear(); for (int i = 0; i < rowInfo.size(); ++i) { const RowInfo& row = rowInfo[i]; if (row.order == -1) { // We've reached the end of valid rows. Resize rowInfo to cut off // this and all further elements. rowInfo.resize(i); break; } QLinkedList<int>& rows = m_trackIdToRows[row.trackId]; rows.push_back(i); } // We're done! Issue the update signals and replace the master maps. if (!rowInfo.isEmpty()) { beginInsertRows(QModelIndex(), 0, rowInfo.size() - 1); m_rowInfo = rowInfo; endInsertRows(); } qDebug() << this << "select() took" << time.elapsed().formatMillisWithUnit() << rowInfo.size(); }
void ConnectionModel::connectionAdded(Connection*) { endInsertRows(); }
void RomModel::addRom(Rom rom) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); romList << rom; endInsertRows(); }
//Insert at this palce void StringListModel::insert(uint place, QString value) { beginInsertRows(QModelIndex(),place,place); _list.insert(place,value); endInsertRows(); }
bool PlaylistModel::handle_change (const Xmms::Dict &chg) { int32_t change = chg.get<int32_t> ("type"); int32_t pos = 0, npos = 0; int32_t id = 0; QString s; if (chg.contains ("position")) { pos = chg.get<int32_t> ("position"); } if (chg.contains ("id")) { #if HAVE_XMMSV id = chg.get<int32_t> ("id"); #else id = chg.get<uint32_t> ("id"); #endif } if (chg.contains ("name")) { s = XClient::stdToQ (chg.get<std::string> ("name")); } if (s != m_name) { return true; } QModelIndex idx = QModelIndex (); switch (change) { case XMMS_PLAYLIST_CHANGED_ADD: beginInsertRows (idx, pos, pos); m_plist.append (id); endInsertRows (); break; case XMMS_PLAYLIST_CHANGED_INSERT: beginInsertRows (idx, pos, pos); m_plist.insert (pos, id); endInsertRows (); break; case XMMS_PLAYLIST_CHANGED_MOVE: npos = chg.get<int32_t> ("newposition"); beginRemoveRows (idx, pos, pos); m_plist.removeAt (pos); endRemoveRows (); beginInsertRows (idx, npos, npos); m_plist.insert (npos, id); endInsertRows (); //if (pos < npos && pos) // pos --; emit entryMoved (index (pos, 0), index (npos, 0)); break; case XMMS_PLAYLIST_CHANGED_REMOVE: m_queue.removeAt(m_queue_index.take(m_plist[pos])); m_client->cache ()->invalidate (m_plist[pos]); beginRemoveRows (idx, pos, pos); m_plist.removeAt (pos); endRemoveRows (); break; case XMMS_PLAYLIST_CHANGED_CLEAR: queueClear(); case XMMS_PLAYLIST_CHANGED_SHUFFLE: case XMMS_PLAYLIST_CHANGED_SORT: m_client->cache ()->invalidate_all (); m_client->playlist ()->listEntries () (Xmms::bind (&PlaylistModel::handle_list, this)); break; } /* TODO: call this only for the necessary methods */ emitTotalPlaytime (); return true; }
void UMemoryModel::fetchMore(const QModelIndex &parent) { beginInsertRows(QModelIndex(), currentRowCount_, currentRowCount_+PageSize-1); currentRowCount_ += PageSize; endInsertRows(); }
void QgsFieldModel::updateModel() { if ( mLayer ) { QgsFields newFields = mLayer->fields(); if ( mFields.toList() != newFields.toList() ) { // Try to handle two special cases: addition of a new field and removal of a field. // It would be better to listen directly to attributeAdded/attributeDeleted // so we would not have to check for addition/removal here. if ( mFields.count() == newFields.count() - 1 ) { QgsFields tmpNewFields = newFields; tmpNewFields.remove( tmpNewFields.count() - 1 ); if ( mFields.toList() == tmpNewFields.toList() ) { // the only change is a new field at the end beginInsertRows( QModelIndex(), mFields.count(), mFields.count() ); mFields = newFields; endInsertRows(); return; } } if ( mFields.count() == newFields.count() + 1 ) { QgsFields tmpOldFields = mFields; tmpOldFields.remove( tmpOldFields.count() - 1 ); if ( tmpOldFields.toList() == newFields.toList() ) { // the only change is a field removed at the end beginRemoveRows( QModelIndex(), mFields.count() - 1, mFields.count() - 1 ); mFields = newFields; endRemoveRows(); return; } for ( int i = 0; i < newFields.count(); ++i ) { if ( mFields.at( i ) != newFields.at( i ) ) { QgsFields tmpOldFields = mFields; tmpOldFields.remove( i ); if ( tmpOldFields.toList() != newFields.toList() ) break; // the change is more complex - go with general case // the only change is a field removed at index i beginRemoveRows( QModelIndex(), i, i ); mFields = newFields; endRemoveRows(); return; } } } // general case with reset - not good - resets selections beginResetModel(); mFields = mLayer->fields(); endResetModel(); } else emit dataChanged( index( 0, 0 ), index( rowCount(), 0 ) ); } else { beginResetModel(); mFields = QgsFields(); endResetModel(); } }
void DataFilesModel::addFile(EsmFile *file) { emit beginInsertRows(QModelIndex(), mFiles.count(), mFiles.count()); mFiles.append(file); emit endInsertRows(); }
void ItemModel::addItem(const Item &item) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); m_items << item; endInsertRows(); }