nodeT* insertNew(nodeT*root, int value) { ///make the actual insertion if (root==NULL) return createNode(value); if (value<root->data) root->left=insertNew(root->left,value); else if (value>root->data) root->right=insertNew(root->right,value); ///update height root->height=max(height(root->left),height(root->right))+1; ///calculating balance factor int bF=balanceFactor(root); ///make the rotation, if necessary if (bF==-2) { if (root->right->data<value) singleLeftRotation(&root); if (root->right->data>value) rightLeftRotation(&root); } else { if (bF==2) { if (root->left->data>value) singleRightRotation(&root); if (root->left->data<value) leftRightRotation(&root); } } return root; }
ToolImage::ToolImage() : Tool(), currentImageElement(NULL), newImageAction(NULL), itMustPlaceNewImage(false) { QVBoxLayout *layout; QToolBar *tool_bar; name = "Image tool"; imageName = ":/images/tool_image.png"; itAcceptsDrop = true; widget = new QWidget(); layout = new QVBoxLayout(); layout->addWidget(new QLabel("Insert:")); tool_bar = new QToolBar(); newImageAction = tool_bar->addAction(QIcon(), "New", this, SLOT(insertNew())); newImageAction->setCheckable(true); layout->addWidget(tool_bar); layout->addWidget(new QLabel("Modify:")); tool_bar = new QToolBar(); tool_bar->addAction(QIcon(), "Change source", this, SLOT(changeSource())); layout->addWidget(tool_bar); widget->setLayout(layout); }
const TCharCanvasDataBase* TCharCanvasDataBase::getCharCanvasData(const VFont& font,int aChar){ TCharCanvasDataKey charKey(font,aChar); TCharBufSet::iterator it=m_charBufSet.find(TEqualCharKey((const TCharCanvasDataKey*)&charKey)); if (it!=m_charBufSet.end()) return copyCharCanvasData((const TCharCanvasDataBase*)((*it).key)); else return insertNew(font,aChar); }
/************ FUNCTION THAT CREATES A PERFECTLY BALANCED BST *******************/ nodeT * createBalancedBST(FILE *f) { nodeT* root=NULL; int data; while (fscanf(f,"%d",&data)!=-1) { root=insertNew(root,data); } return root; }
void ToolImage::onMousePress(const Qt::MouseButton /*button*/, const Vector2f &/*position*/) { if (itMustPlaceNewImage) { Element *element = RocketHelper::getElementUnderMouse(); if ((element = ToolDiv::getDivParent(element))) { QString imageName; if (getImageNameFromFileSystem(imageName)) { Rocket::Core::XMLAttributes attributes; attributes.Set("src", imageName.toAscii().data()); Element *img = Rocket::Core::Factory::InstanceElement(NULL, "img", "img", attributes); insertNew(img, element); } } itMustPlaceNewImage = false; newImageAction->setChecked(false); } }
int OrderList::add(ListEntry *node, AddCode where, bool mvcursor) { int status = OLIST_OK; if (node != NULL) { if (f_cursor == NULL) insertNew(node); else { switch (where) { case addAfter: if (f_cursor == f_tail) insertTail(node); else insertAfter(node); break; case addBefore: if (f_cursor == f_head) insertHead(node); else insertBefore(node); break; case addHead: insertHead(node); break; case addTail: insertTail(node); break; default: return OLIST_ERROR; } } if ((mvcursor) || (f_cursor == NULL)) f_cursor = node; } else return OLIST_ERROR; f_size++; return OLIST_OK; }
void ToolImage::onFileDrop(const QString &url) { QFileInfo fileInfo(url); Element *element = RocketHelper::getElementUnderMouse(); if (element) { if (element->GetTagName() == "img") { changeSource(element,fileInfo.fileName()); } else { element = ToolDiv::getDivParent(element); if (element) { Rocket::Core::XMLAttributes attributes; attributes.Set("src", fileInfo.fileName().toAscii().data()); Element* img = Rocket::Core::Factory::InstanceElement(NULL, "img", "img", attributes); insertNew(img, element); } } } }
File * FilesModel::appendNew(const QUrl &path) { return insertNew(rowCount(), path); }
Folder * FoldersModel::appendNew(const QUrl &path) { return insertNew(rowCount(), path); }