void FunctionManager::copyFunction(t_function_id fid) { Function* function = _app->doc()->function(fid); Q_ASSERT(function != NULL); /* Attempt to create a copy of the function to Doc */ Function* copy = function->createCopy(_app->doc()); if (copy != NULL) { /* Create a new item for the copied function */ QTreeWidgetItem* item; item = new QTreeWidgetItem(m_tree); updateFunctionItem(item, copy); } else if (_app->doc()->functions() >= KFunctionArraySize) { QMessageBox::critical(this, tr("Too many functions"), tr("You can't create more than %1 functions.") .arg(KFunctionArraySize)); } else { QMessageBox::critical(this, tr("Function creation failed"), tr("Unable to create new function.")); } }
void FunctionManager::addFunction(Function* function) { QTreeWidgetItem* item; Q_ASSERT(function != NULL); /* Create a new item for the function */ item = new QTreeWidgetItem(m_tree); updateFunctionItem(item, function); /* Clear current selection and select only the new one */ m_tree->clearSelection(); item->setSelected(true); /* Start editing immediately */ if (slotEdit() == QDialog::Rejected) { /* Edit dialog was rejected -> delete function */ deleteSelectedFunctions(); } else { m_tree->sortItems(KColumnName, Qt::AscendingOrder); m_tree->scrollToItem(item); } }
void FunctionManager::slotBusTriggered(QAction* action) { quint32 bus; Q_ASSERT(action != NULL); bus = action->data().toUInt(); /* Set the selected bus to all selected functions */ QListIterator <QTreeWidgetItem*> it(m_tree->selectedItems()); while (it.hasNext() == true) { QTreeWidgetItem* item; Function* function; item = it.next(); Q_ASSERT(item != NULL); function = _app->doc()->function(item->text(KColumnID).toInt()); Q_ASSERT(function != NULL); function->setBus(bus); updateFunctionItem(item, function); } }
void FunctionsTreeWidget::updateTree() { blockSignals(true); clearTree(); foreach (Function* function, m_doc->functions()) updateFunctionItem(new QTreeWidgetItem(parentItem(function)), function); blockSignals(false); }
void FunctionsTreeWidget::functionChanged(quint32 fid) { blockSignals(true); Function* function = m_doc->function(fid); if (function == NULL) return; QTreeWidgetItem* item = functionItem(function); if (item != NULL) updateFunctionItem(item, function); blockSignals(false); }
void FunctionsTreeWidget::functionAdded(quint32 fid) { blockSignals(true); Function* function = m_doc->function(fid); if (function == NULL) return; QTreeWidgetItem* parent = parentItem(function); QTreeWidgetItem* item = new QTreeWidgetItem(parent); updateFunctionItem(item, function); function->setPath(parent->text(COL_PATH)); blockSignals(false); }
void FunctionManager::updateTree() { m_tree->clear(); for (t_function_id fid = 0; fid < KFunctionArraySize; fid++) { Function* function = _app->doc()->function(fid); if (function != NULL) { QTreeWidgetItem* item; item = new QTreeWidgetItem(m_tree); updateFunctionItem(item, function); } } }
QTreeWidgetItem *FunctionsTreeWidget::addFunction(quint32 fid) { blockSignals(true); Function* function = m_doc->function(fid); if (function == NULL) { blockSignals(false); return NULL; } QTreeWidgetItem* parent = parentItem(function); QTreeWidgetItem* item = new QTreeWidgetItem(parent); updateFunctionItem(item, function); if (parent != NULL) function->setPath(parent->text(COL_PATH)); blockSignals(false); return item; }
int FunctionManager::slotEdit() { QTreeWidgetItem* item; Function* function; int result; if (m_tree->selectedItems().isEmpty() == true) return QDialog::Rejected; item = m_tree->selectedItems().first(); Q_ASSERT(item != NULL); // Find the selected function function = _app->doc()->function(item->text(KColumnID).toInt()); if (function == NULL) return QDialog::Rejected; // Edit the selected function result = editFunction(function); updateFunctionItem(item, function); return result; }