void toResultModelEdit::deleteRow(QModelIndex index) { if (!index.isValid() || index.row() >= Rows.size()) return; toQueryAbstr::Row deleted = Rows[index.row()]; toRowDesc rowDesc = deleted[0].getRowDesc(); if (rowDesc.status == REMOVED) { //Make sure removed row can't be removed twice return; } else if (rowDesc.status == ADDED) { //Newly added record can be removed regularly beginRemoveRows(QModelIndex(), index.row(), index.row()); Rows.takeAt(index.row()); endRemoveRows(); } else //Existed and Modified { rowDesc.status = REMOVED; Rows[index.row()][0] = toQValue(rowDesc); } recordDelete(deleted); }
void toResultStorage::query(void) { if (!handled() || Tablespaces || Files) return ; try { saveSelected(); clear(); toConnection &conn = connection(); toQList args; toPush(args, toQValue(toSizeDecode(Unit))); TablespaceValues.clear(); FileValues.clear(); Tablespaces = new toNoBlockQuery(conn, toQuery::Background, toSQL::string(ShowCoalesced ? SQLShowCoalesced : SQLNoShowCoalesced, connection()), args); Files = NULL; Files = new toNoBlockQuery(conn, toQuery::Background, toSQL::string(SQLDatafile, connection()), args); Poll.start(100); } TOCATCH }
int toResultModelEdit::addRow(QModelIndex ind, bool duplicate) { int newRowPos; if (ind.isValid()) newRowPos = ind.row() + 1; // new row is inserted right after the current one else { if (!duplicate || Rows.size() > 0) newRowPos = Rows.size() + 1; // new row is appended at the end else return -1; // unable to duplicate a record if there are no records } beginInsertRows(QModelIndex(), newRowPos, newRowPos); toQueryAbstr::Row row; toRowDesc rowDesc; rowDesc.key = CurrRowKey++; rowDesc.status = ADDED; if (duplicate) { // Create a duplicate of current row row = Rows[ind.row()]; // Reset a 0'th column row[0] = rowDesc; } else { // Create a new empty row row.append(toQValue(rowDesc)); // null out the rest of the row int cols = Headers.size(); for (int j = 1; j < cols; j++) row.append(toQValue()); } Rows.insert(newRowPos, row); endInsertRows(); recordAdd(row); return newRowPos; } // addRow
void toProfiler::changeObject(void) { toTreeWidgetItem *qi = Units->selectedItem(); toResultViewItem *item = qi ? dynamic_cast<toResultViewItem *>(qi) : NULL; if (item) { toQList par; toPush(par, toQValue(item->allText(0))); toPush(par, toQValue(item->allText(1))); toPush(par, toQValue(item->allText(4))); toPush(par, toQValue(item->allText(5))); toPush(par, toQValue(item->allText(6))); Lines->clearTotals(); try { Lines->query(toSQL::string(SQLListSource, connection()), par); } TOCATCH } }
toTemporary::toTemporary(QWidget *main, toConnection &connection) : toToolWidget(TemporaryTool, "temporary.html", main, connection, "toTemporary") , ToolMenu(NULL) { QToolBar *toolbar = Utils::toAllocBar(this, tr("Temporary Objects")); layout()->addWidget(toolbar); refreshAct = toolbar->addAction(QIcon(QPixmap(const_cast<const char**>(refresh_xpm))), tr("Refresh list"), this, SLOT(refresh())); toolbar->addWidget(new Utils::toSpacer()); new toChangeConnection(toolbar); QSplitter *splitter = new QSplitter(Qt::Vertical, this); layout()->addWidget(splitter); Objects = new toResultTableView(true, false, splitter, "columnView"); Objects->setSQL(SQLListTemporaryObjects); Objects->setReadAll(true); Objects->setSelectionBehavior(QAbstractItemView::SelectRows); QList<int> list; list.append(75); splitter->setSizes(list); QString unit(toConfigurationNewSingle::Instance().option(ToConfiguration::Global::SizeUnit).toString()); toQueryParams args = toQueryParams() << toQValue(Utils::toSizeDecode(unit)) << toQValue(unit); Objects->refreshWithParams(args); connect(Objects, SIGNAL(selectionChanged()), this, SLOT(changeItem())); Statement = new toSGAStatement(splitter); setFocusProxy(Objects); }
void toResultModelEdit::clearStatus() { // Go through all records and set their status to be existed for (toQueryAbstr::RowList::iterator ite = Rows.begin(); ite != Rows.end(); ite++) { toRowDesc rowDesc = ite->at(0).getRowDesc(); if (rowDesc.status == REMOVED) { ite = Rows.erase(ite); if (ite == Rows.end()) break; } else if (rowDesc.status != EXISTED) { rowDesc.status = EXISTED; (*ite)[0] = toQValue(rowDesc); } } emit headerDataChanged(Qt::Vertical, 0, Rows.size() - 1); }
void toResultStorage::query(const QString &sql, toQueryParams const& param) { Q_UNUSED(sql); Q_UNUSED(param); if (!handled() || Tablespaces || Files) return ; try { saveSelected(); clear(); toConnection &conn = connection(); toQueryParams args; args << toQValue(Utils::toSizeDecode(Unit)); TablespaceValues.clear(); FileValues.clear(); Tablespaces = new toEventQuery(this , conn , toSQL::string(ShowCoalesced ? SQLShowCoalesced : SQLNoShowCoalesced, connection()) , args , toEventQuery::READ_ALL); connect(Tablespaces, SIGNAL(dataAvailable(toEventQuery*)), this, SLOT(slotPollTablespaces())); connect(Tablespaces, SIGNAL(done(toEventQuery*)), this, SLOT(slotDoneTablespaces())); Tablespaces->start(); Files = new toEventQuery(this , conn , toSQL::string(SQLDatafile, connection()) , args , toEventQuery::READ_ALL); connect(Files, SIGNAL(dataAvailable(toEventQuery*)), this, SLOT(slotPollFiles())); connect(Files, SIGNAL(done(toEventQuery*)), this, SLOT(slotDoneFiles())); Files->start(); } TOCATCH }
toResultModel::toResultModel(const QString &owner, const QString &type, QObject *parent, bool read) : QAbstractTableModel(parent) , Query(NULL) , SortedOnColumn(-1) , SortedOrder(Qt::AscendingOrder) , CurrRowKey(1) , ReadableColumns(read) , First(true) , HeadersRead(false) , ReadAll(false) { MaxRowsToAdd = MaxRows = toConfigurationNewSingle::Instance().option(ToConfiguration::Database::InitialFetchInt).toInt(); #if QT_VERSION < 0x050000 setSupportedDragActions(Qt::CopyAction); #endif // Manually add two columns (first one will be invisible) // NOTE: If this function is used to display say table columns from the cache // it will have to be modified to set header dynamically according to type of // data displayed. struct HeaderDesc d; d.name = "#"; d.name_orig = d.name; d.align = Qt::AlignRight; d.datatype = "INT"; Headers.append(d); d.name = type + " name (cached)"; d.name_orig = type + " name"; d.align = Qt::AlignLeft; d.datatype = "CHAR"; Headers.append(d); HeadersRead = true; // Fetch list of objects from the cache QList<toCache::CacheEntry const*> tmp = toConnection::currentConnection(this).getCache().getEntriesInSchema(owner, type); beginInsertRows(QModelIndex(), 0, tmp.count()); // Convert list of objects to appropriate type toQueryAbstr::Row row; int counter = 1; for (QList<toCache::CacheEntry const*>::iterator i = tmp.begin(); i != tmp.end(); i++) { // For each row a mandatory rownumber integer should be added toRowDesc rowDesc; rowDesc.key = counter++; rowDesc.status = EXISTED; row.append(toQValue(rowDesc)); //row.append(toQValue(counter++)); // Copy all values of a record ////for (toCache::Row::iterator ii = (*i).begin(); ii != (*i).end(); ii++) ///{ /// row.append((*ii).toString()); ///} row.append((*i)->name.second); Rows.append(row); row.clear(); } endInsertRows(); }
void toResultModel::slotReadData() { if (!Query) { cleanup(); return; } try { // must check for errors Query->eof(); int cols = Headers.size(); if (cols < 1) return; // don't actually modify any data until we can call // beginInsertRows(). but to do that, we have to know how many // records we're going to add. toQueryAbstr::RowList tmp; int current = Rows.size(); while (Query->hasMore() && (MaxRows < 0 || MaxRows > current)) { toQueryAbstr::Row row; // The number column (rowKey). should never change toRowDesc rowDesc; rowDesc.key = CurrRowKey++; rowDesc.status = EXISTED; row.append(toQValue(rowDesc)); //row.append(toQValue(CurrRowKey++)); for (int j = 1; (j < cols || j == 0) && Query->hasMore(); j++) row.append(Query->readValue()); tmp.append(row); current++; } // if we read some data, then go ahead and insert them now. if (tmp.size() > 0) { beginInsertRows(QModelIndex(), Rows.size(), current - 1); Rows << tmp; endInsertRows(); } // not really first, but just be sure to emit before done() // must be emitted even if there's no data.... if (First) { if (tmp.size() > 0 || !Query || Query->eof()) { First = !First; // need to reset view(s) since we have to poll for data beginResetModel(); endResetModel(); if (Query && Query->rowsProcessed() > 0) { emit firstResult(QString::number(Query->rowsProcessed()) + (Query->rowsProcessed() == 1 ? tr(" row processed") : tr(" rows processed")), false); } else emit firstResult(tr("Statement executed"), false); } } if (!Query) return; if (!Query->hasMore() && Query->eof()) { cleanup(); return; } } catch (const toConnection::exception &str) { if (First) { First = !First; emit firstResult(str, true); } Utils::toStatusMessage(str); cleanup(); return; } catch (const QString &str) { if (First) { First = !First; emit firstResult(str, true); } Utils::toStatusMessage(str); cleanup(); return; } }