示例#1
0
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;
}
示例#2
0
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);
}
示例#3
0
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);
}
示例#4
0
/************ 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;
}
示例#5
0
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);
    }
}
示例#6
0
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;
}
示例#7
0
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);
            }
        }
    }
}
示例#8
0
File * FilesModel::appendNew(const QUrl &path)
{
    return insertNew(rowCount(), path);
}
示例#9
0
Folder * FoldersModel::appendNew(const QUrl &path)
{
    return insertNew(rowCount(), path);
}