DNODE* insertWordNode(char* key,int hash_val,DNODE* findnode){ DNODE* new_node=createDictNode(key,0); if(dict->hash[hash_val]==0){ dict->hash[hash_val]=new_node; return insertList(dict, new_node, dict->end); } //just scan the last node of the double like list to NULL if(dict->hash[hash_val]!=0 && findnode==0) return insertList(dict, new_node, dict->hash[hash_val]); return insertList(dict, new_node, findnode->prev); }
bool ListBoxDnd::mouseMoveEvent( QMouseEvent * event ) { if ( event->state() & LeftButton ) { if ( ( event->pos() - mousePressPos ).manhattanLength() > 3 ) { ListBoxItemList list; buildList( list ); ListBoxItemDrag * dragobject = new ListBoxItemDrag( list, (dMode & Internal), (QListBox *) src ); // Emit signal for all dragged items QListBoxItem * i = list.first(); while ( i ) { emit dragged( i ); i = list.next(); } if ( dMode & Move ) { removeList( list ); // "hide" items } dragobject->dragCopy(); if ( dMode & Move ) { if ( dropConfirmed ) { // ###FIX: memleak ? in internal mode, only pointers are transfered... //list.setAutoDelete( TRUE ); list.clear(); dropConfirmed = FALSE; } insertList( list ); // "show" items } } } return FALSE; }
/** * Stores a word in the hash-list. * * @param hl A HashList structure * @param str The string to be saved * @param str_len Length of the string * @returns Whether the word has been stored, or simply incremented the word counter */ int hl_add_word(HashList *hl, char *str, int str_len) { int h, r; char *copybuffer; List *l; ListData *ld; h = hash(str, str_len, hl->size); // printf("[%16s] Calculated hash for [%s]: [%d]\n", "hl_add_word", str, h); l = &(hl->buckets[h]); ld = findList(l, str); if ( ld != NULL ) { ld->numTimes++; r = 1; } else { copybuffer = malloc((strlen(str) + 1 ) * sizeof(char)); strcpy(copybuffer, str); ld = malloc(sizeof(ListData)); ld->primary_key = copybuffer; ld->numTimes = 1; insertList(l, ld); r = 0; } return r; }
void ParticleContainerLC::add(Particle& p) { particles.push_back(p); resetIterator(); // define index of cell for particle #if 1==DIM int particleIndex[]= {p.getX()[0]/radius, p.getX()[1]/radius, p.getX()[2] / radius}; #elif 2==DIM int particleIndex[]= {p.getX()[0]/radius, p.getX()[1]/radius, p.getX()[2] / radius}; #elif 3==DIM int particleIndex[] = { p.getX()[0] / cellsSize[0], p.getX()[1] / cellsSize[1], p.getX()[2] / cellsSize[2] }; #endif // skip particles that don't suite into the domain bool outofbound = false; for (int d = 0; d < 3; d++) { if (particleIndex[d] >= cellNums[d] || particleIndex[d] < 0 || p.getX()[d] < 0.0 || p.getX()[d] > domainSize[d]) outofbound = true; } if (outofbound) return; ParticleList* pl = new ParticleList;; pl->p = &p; pl->next = NULL; insertList((ParticleList**)&(cells[calcIndex(particleIndex, cellNums)].root), pl); }
//insert new node into table void insertTable(HashTable *hashTable, Record *rec) { LinkedList *list; int i; //hash function will use ascii values, thats why we have 36 slots in the table //they will work as array indices, because i know how hash tables //letters from 0-26, numbers from 27-36 int ascZero = 48; int ascA = 97; i = isalpha(rec->token[0]) == 0 ? (int)rec->token[0] - ascZero + 26 : ((int)rec->token[0] - ascA); //printf("trying to insert %s at location %d\n", rec->token, i); list = hashTable->boxes[i]; if(list == NULL) { hashTable->boxes[i] = createList(equals); } insertList(hashTable->boxes[i], rec); }
MainWindow::MainWindow() { QMenu *fileMenu = new QMenu(tr("&File")); fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence(tr("Ctrl+Q", "File|Exit"))); QMenu *actionsMenu = new QMenu(tr("&Actions")); actionsMenu->addAction(tr("&Highlight List Items"), this, SLOT(highlightListItems())); actionsMenu->addAction(tr("&Show Current List"), this, SLOT(showList())); QMenu *insertMenu = new QMenu(tr("&Insert")); insertMenu->addAction(tr("&List"), this, SLOT(insertList()), QKeySequence(tr("Ctrl+L", "Insert|List"))); menuBar()->addMenu(fileMenu); menuBar()->addMenu(insertMenu); menuBar()->addMenu(actionsMenu); editor = new QTextEdit(this); document = new QTextDocument(this); editor->setDocument(document); setCentralWidget(editor); setWindowTitle(tr("Text Document List Items")); }
int main() { linknode *flist,*rlist,*find; int index; char value; rlist=(linknode*)malloc(sizeof(linknode)); rlist->next=NULL; printf("plase input a sting,end with the KEY_Enter \n"); //flist=CreateListF(); //printLinkList(flist); CreateListR(rlist); printLinkList(rlist); printf("list length=%d \n",getLength(rlist)); printf("set insert node:index,value:"); scanf("%d,%c",&index,&value); printf("insert a element!"); insertList(rlist,value,index); printLinkList(rlist); printf("list length=%d \n",getLength(rlist)); printf("set delete node index:"); scanf("%d",&index); deleteList(rlist,index); printf("delete a element!"); printLinkList(rlist); printf("list length=%d \n",getLength(rlist)); printf("set visit node index:"); scanf("%d",&index); find=getNode(rlist,index); if(find!=NULL) { printf("this node value=%c \n",find->data); } return 0; }
void enQueue(struct Queue* q, struct TreeNode* node, int level){ printf("enQueue: %d, %d\n", node->val, level); struct ListNodeLevel *newNode = malloc(sizeof(struct ListNodeLevel)); newNode->val = node; newNode->level = level; newNode->next = NULL; struct ListNodeLevel *newHead = insertList(q->head, newNode); q->head = newHead; }
int main() { dlinklist *head; int num; printf("please input node num\n"); scanf("%d", &num); head = createList(num); printList(head); printList(insertList(head, 2)); printList(deleteList(head, 2)); return 0; }
//prints the path of the a-star void printAstar(int x, int y, int dirt, int heuristic){ tree t; if(dirt > 0){ t = astar(x, y, dirt, heuristic); if(t == NULL) printf("no solution found\n"); else{ //inserts the actions in a list while(t -> action != 'X'){ //lowercase mean it can vacuum if(t -> action > 96){ insertList('V'); t -> action = t -> action - 32; } //inserts in the list insertList(t -> action); t = t -> parent; } //free the memory freeTree(t); //print it printList(); printf("%d nodes generated\n", generated); printf("%d nodes expanded\n", expanded); } } //no dirt in the matrix, there is nothing to do else{ printf("%d nodes generated\n", generated); printf("%d nodes expanded\n", expanded); } }
//============================================================================== void AztecDVBR_Matrix::calcRemoteInds(int*& remoteInds, int& len) { // //Form a list of the block column indices that are not in the local //update set. // int nnzBlks = Amat_->bpntr[amap_->getNumLocalBlocks()]; int local; for(int i=0; i<nnzBlks; i++) { if (!inUpdate(Amat_->bindx[i], local)) { insertList(Amat_->bindx[i], remoteInds, len); } } }
int main() { pNode list1,list2; initList(&list1); initList(&list2); printf("Please input %d numbers in list:\n",N); int i, elem; for(i=0;i<N;++i) { scanf("%d",&elem); insertList(&list1,elem); } showList("List1",list1); printf("Please input %d numbers in list2:\n"); for(i=0;i<N;++i){ scanf("%d",&elem); insertList(&list2,elem); } showList("List2",list2); fun(&list1,&list2); showList("After delete",list1); return 0; }
/* *This function creat a list with random values between 0 and 100; * The list's length is passed on the parameter * */ nodePointer createRandomList( int lenght) { nodePointer list = NULL; int index; srand(time(NULL)); list = malloc(sizeof(ListNode)); list->value = rand()%100; for(index = 1; index < lenght; index++){ nodePointer newNode = malloc(sizeof(ListNode)); newNode->value = rand()%100; newNode->nextNode = NULL; insertList(list,newNode); } return list; }
/** * Cria números aleatóriamente * @param l elemento do tipo t_lista * @param n número de interações */ void createTest(t_lista *l, int n) { int i, v[n]; for (i = 0; i <= n; i++) v[i] = rand() % 2; for (i = 0; i < n; i++) printf("%d", v[i]); printf("\n"); for (i = 0; i < n; i++) if (v[i] == 1) { insertList(l); } else { if (! isEmptyList(l)) removeList(l); } }
void main(){ node_t *head=NULL; int arr[7] = {1,2,3,4,5,6,7}; insertSortedArrayToBST(&head,arr,0,6); printPreOrderNode(head); //printf("Height : %d",maxDepth(head)); int height = maxDepth(head); int iterator=0; for(iterator=0;iterator<height;iterator++){ insertList(&head,iterator); } }
int main() { pNode list1,list2; initList(&list1); initList(&list2); printf("Please input %d numbers to create list:\n",N); int i,elem; for(i=0;i<N;++i) { scanf("%d",&elem); insertList(&list1,elem); } showList("Before split",list1); fun(&list1,&list2); showList("After split,List1",list1); showList("After split,List2",list2); return 0; }
MainWindow::MainWindow() { QMenu *fileMenu = new QMenu(tr("&File")); fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence(tr("Ctrl+Q", "File|Exit"))); QMenu *editMenu = new QMenu(tr("&Edit")); cutAction = editMenu->addAction(tr("Cu&t"), this, SLOT(cutSelection()), QKeySequence(tr("Ctrl+X", "Edit|Cut"))); copyAction = editMenu->addAction(tr("&Copy"), this, SLOT(copySelection()), QKeySequence(tr("Ctrl+C", "Edit|Copy"))); pasteAction = editMenu->addAction(tr("&Paste"), this, SLOT(pasteSelection()), QKeySequence(tr("Ctrl+V", "Edit|Paste"))); QMenu *selectMenu = new QMenu(tr("&Select")); selectMenu->addAction(tr("&Word"), this, SLOT(selectWord())); selectMenu->addAction(tr("&Line"), this, SLOT(selectLine())); selectMenu->addAction(tr("&Block"), this, SLOT(selectBlock())); selectMenu->addAction(tr("&Frame"), this, SLOT(selectFrame())); QMenu *insertMenu = new QMenu(tr("&Insert")); insertMenu->addAction(tr("&List"), this, SLOT(insertList()), QKeySequence(tr("Ctrl+L", "Insert|List"))); menuBar()->addMenu(fileMenu); menuBar()->addMenu(editMenu); menuBar()->addMenu(selectMenu); menuBar()->addMenu(insertMenu); editor = new QTextEdit(this); document = new QTextDocument(this); editor->setDocument(document); connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); updateMenus(); setCentralWidget(editor); setWindowTitle(tr("Text Document Writer")); }
void ParticleContainerLC::moveParticles_LC(Cell** cell_arr, int *nc, double *l) { int dim = DIM; int ic[dim], kc[dim]; for (ic[0] = 1; ic[0] < nc[0]-1; ic[0]++) for (ic[1] = 1; ic[1] < nc[1]-1; ic[1]++) #if 3==DIM for (ic[2] = 1; ic[2] < nc[2]-1; ic[2]++) #endif { //LOG4CXX_DEBUG(particlelog, "move() index: " << calcIndex(ic, nc) << " of " << numcell(allCellNums)); ParticleList **q = &cell_arr[calcIndex(ic, nc)]->root; // get cell/ first ParticleList at index ic ParticleList *i = *q; //LOG4CXX_DEBUG(particlelog, "got i in move():" << q); while (NULL != i) { Particle& p = *i->p; // kc: 3d index of cell which has to store i->p according to the X vector of p //LOG4CXX_DEBUG(particlelog, "next p in move():" << i->p->getX().toString()); utils::Vector<double, 3> X = p.getX(); for (int d = 0; d < DIM; d++) { int coord = ((int) floor(X[d] / cellsSize[d])) + 1; // +1 for transformation from cells[] to allCells[] coords. kc[d] = coord < nc[d] ? (coord < 0 ? 0.0 : coord) : nc[d]-1; // indices must fit into cell_arr[] } if ((ic[0] != kc[0]) || (ic[1] != kc[1]) #if 3==DIM || (ic[2] != kc[2]) #endif ) { //LOG4CXX_DEBUG(particlelog, "moving from "<<ic[0]<<","<<ic[1]<<","<<ic[2] << " to " <<kc[0]<<","<<kc[1]<<","<<kc[2]); // move particle into cell kc deleteList(q); //LOG4CXX_DEBUG(particlelog, "deleted from old cell; old index:" << calcIndex(ic, nc) << "; new index:" << calcIndex(kc, nc)); insertList(&cell_arr[calcIndex(kc, nc)]->root, i); //LOG4CXX_DEBUG(particlelog, "inserted in new cell"); } else {//LOG4CXX_DEBUG(particlelog, "next p in move()"); q = &i->next; } i = *q; } } }
void insertWord_HashTable(List * tablaHash, char * subcadena){ int valor_hash, n_lletres; ListData *listData; n_lletres = (int)strlen(subcadena); if ( n_lletres > max_word ) max_word = n_lletres; valor_hash = funcHash(subcadena); /* Search if the key is in the tree */ listData = findList(&tablaHash[valor_hash], subcadena); if(listData != NULL){ /* We increase it the number of times that shows up */ listData->numTimes++; }else{ /* If the key is not in the list, allocate memory for the data and insert it in the list */ listData = malloc(sizeof(ListData)); listData->key = malloc(sizeof(TYPEKEY) * MAXWORD); strcpy(listData->key, subcadena); listData->numTimes = 1; insertList(&tablaHash[valor_hash], listData); } }
void Prefs_DocumentSetup::setupPageSizes(struct ApplicationPrefs *prefsData) { PageSize ps(prefsData->docSetupPrefs.pageSize); QStringList insertList(ps.activeSizeList()); QStringList insertTrList(ps.activeSizeTRList()); prefsPageSizeName = prefsData->docSetupPrefs.pageSize; if (insertList.indexOf(prefsPageSizeName) ==-1) { insertList << prefsPageSizeName; insertTrList << prefsPageSizeName; } QMap<QString, QString> insertMap; for (int i = 0; i < insertTrList.count(); ++i) { QString key = insertTrList.at(i); insertMap[key] = insertList.at(i); } insertTrList.sort(); pageSizeComboBox->clear(); for (int i = 0; i < insertList.count(); ++i) { QString key = insertTrList.at(i); pageSizeComboBox->addItem(key, insertMap[key]); } pageSizeComboBox->addItem(CommonStrings::trCustomPageSize, CommonStrings::customPageSize); QString pageSizeName = CommonStrings::trCustomPageSize; int index = pageSizeComboBox->findData(prefsPageSizeName); if (index >= 0) pageSizeName = pageSizeComboBox->itemText(index); setCurrentComboItem(pageSizeComboBox, pageSizeName); marginsWidget->setPageSize(prefsPageSizeName); bleedsWidget->setPageSize(prefsPageSizeName); }
void RecoveryByL2::initVerThreeSeparateRelation() { List *verneighborvertail = NULL; int i, j, num; vector<int>v; verThreeSeparateRelation = new List*[(int)meshmodel->numvertices * 3]; if(NULL == verThreeSeparateRelation){ printf("error in RecoveryByL2::initVerThreeSeparateRelation ------->\n"); return; } for(i = 0;i < (int)meshmodel->numvertices * 3;i++){ verThreeSeparateRelation[i] = NULL; } initVerNeighborVer(); for(i = 0;i < (int)meshmodel->numvertices;i++){ verneighborvertail = verNeighborVer[i]; v.clear(); num = 0; while(verneighborvertail){ for(j = 0;j < 3;j++){ v.push_back(3 * verneighborvertail->data + j); num++; } verneighborvertail = verneighborvertail->next; } for(j = 0;j < 3;j++){ insertList(verThreeSeparateRelation, 3 * i + j, v, num); } } delVerNeighborVer(); }
bool Tracker::update(cv::Mat &sourceImage) { if(targetTrackerlet == 0)//当前targetTrackerlet为空,在最初跟踪目标确定阶段调用 { if(lockedPedArea->next != NULL)//这里需要假定在视频的初始阶段有且仅有目标行人出现并可检测,这一限定条件 { Trackerlet* trackerlet = new Trackerlet(); extractTracklet(sourceImage,lockedPedArea->next,trackerlet); trackerlet->occupied++; targetTrackerlet = trackerlet;//这里因为之前没有存在traget,这里可以直接赋值,没有问题 //在原图上进行绘制,红色表示测量值 circle(sourceImage,cv::Point(trackerlet->topLeftX,trackerlet->topLeftY),5,CV_RGB(255,0,0),3); cv::rectangle(sourceImage, cv::Rect(trackerlet->topLeftX,trackerlet->topLeftY,targetTrackerlet->width,targetTrackerlet->height), cv::Scalar(255,0,0),2); //根据当前检测值对kalman进行修正,这里的predict必须添加,但这里的预测结果是没有不关心的,因为存在检测值 Mat prediction = KF.predict(); measurement.at<float>(0) = (float)trackerlet->topLeftX; measurement.at<float>(1) = (float)trackerlet->topLeftY; KF.correct(measurement);//利用当前测量值对其滤波器进行修正 //这里直接认定检测得到就是正确的显然是存在问题的,只能这样认为,否则无法对跟踪目标进行指定 //遍历删除操作 LockedArea *head = lockedPedArea; LockedArea *current = lockedPedArea->next; while(current != NULL) { LockedArea* tmp = current; head->next = current->next; delete tmp; current = head->next; } return false; } else { return true;//表示当前不存在检测矩形框,需要进一步的检测过程, } } else//当前targetTrackerlet存在,可以进行比较、预测过程 { Trackerlet* newTargetTrackerlet = NULL;//用于存储新得到tracklet,无论是检测得到还是预测得到 //首先对lockedPedArea进行遍历判断,两个结果:一个是发现targetTrackerlet,另外就是没有发现,好像废话,,, LockedArea* current = lockedPedArea->next;//遍历判断 if(current != NULL)//当检测到行人时 { while(current != NULL) { Trackerlet* trackerlet = new Trackerlet(); extractTracklet(sourceImage,current,trackerlet); //认定为目标行人,阈值后续观察后再进行调节,这里需要加入位置信息 if(isTargetTrackerlet(trackerlet)) { //绘制 circle(sourceImage,cv::Point(trackerlet->topLeftX,trackerlet->topLeftY),5,CV_RGB(255,0,0),3); //只能使用测量值对滤波器进行修正,不能够使用预测值进行修正,那样是不对的 measurement.at<float>(0) = (float)trackerlet->topLeftX; measurement.at<float>(1) = (float)trackerlet->topLeftY; KF.correct(measurement); //临时存储 newTargetTrackerlet = trackerlet;//仅仅是将当前相似trackerlet保存下来,还没有进行替换targetTrackerlet过程 //move2next current = current->next; break; } else//加入distrator列表,同时将其加入到targetTarcker中后方 { insertList(trackerlet); insertDistrator(trackerlet); //发现问题了,这里将内容存储到distrator中,同时存放到trakerletList,当一遍消除是,另一边将发生意外, //因此这里需要对双方进行约束,是进行删除,还是进行简单移除,需要进行判定, current = current->next; } } //将剩余tracklet放入distrator while(current != NULL) { Trackerlet* trackerlet = new Trackerlet(); extractTracklet(sourceImage,current,trackerlet); insertList(trackerlet); insertDistrator(trackerlet); current = current->next; } //使用结束之后,清空lockedPedArea操作,遍历删除 LockedArea *head = lockedPedArea; current = lockedPedArea->next; while(current != NULL) { LockedArea* tmp = current; head->next = current->next; delete tmp; current = head->next; } } if(newTargetTrackerlet == NULL)//之前经由lockedPedArea,并没有得到可用的trackerlet,需要经由kalman进行滤波预测 { Mat prediction = KF.predict();//利用滤波器对当前检测tracklet矩形进行预测 float *data = prediction.ptr<float>(0); int predictX = data[0]; int predictY = data[1]; cv::Mat subImage = sourceImage(cv::Rect(predictX,predictY,targetTrackerlet->width,targetTrackerlet->height)); blockFeature target; extractor.computeFeature(subImage,target); //将当前得到blockfeature与之前存储内容进行比较 double distinguishValue = this->distinguish(targetTrackerlet->featureSet,target); std::cout<<"预测trackerlet差异值为:"<<distinguishValue<<std::endl; if(distinguishValue > 1.0)//当前预测结果并不能满足相似度要求,发出检测请求 return true; else { //将预测结果保存下来 Trackerlet* trackerlet = new Trackerlet(); letNumber++; trackerlet->trackerletID = letNumber;//这个ID暂时没有什么意义,先临时放在这里 trackerlet->topLeftX = predictX; trackerlet->topLeftY = predictY; trackerlet->width = targetTrackerlet->width; trackerlet->height = targetTrackerlet->height; trackerlet->setBlockFeature(target); trackerlet->next = NULL; trackerlet->occupied = 0; newTargetTrackerlet = trackerlet;//临时存储新近得到targetTrackerlet //在原图上进行绘制,绿色表示预测值 circle(sourceImage,cv::Point(predictX,predictY),5,CV_RGB(0,255,0),3); cv::rectangle(sourceImage, cv::Rect(predictX,predictY,targetTrackerlet->width,targetTrackerlet->height), cv::Scalar(255,0,0),2); //这里需要仔细看一下,这样做可以么?会不会指向同一位置的内容被改变呢,不会的 } } //这里将targetTrackerlet内容使用newTargetTrackerlet进行替代,同时保证原始列表内容不变 newTargetTrackerlet->next = targetTrackerlet->next; targetTrackerlet->next = NULL; Trackerlet* tmp = targetTrackerlet; tmp->occupied--; if(tmp->occupied == 0) { delete tmp;//这里可以直接进行删除操作么?有没有可能被其他占有呢?可以直接删除 letNumber--; } newTargetTrackerlet->occupied++; targetTrackerlet = newTargetTrackerlet; //终于到这里了,根据三方内容进行权重调节 featureWeighting(targetTrackerlet->featureSet); //必定不会严格按照你的所有想法展开,因此在设计算法的时候要有足够的鲁棒性才可以 //每个阶段对targetTrackerlet进行一次更新,这里的内容还不是特别明确,是否在每个阶段的末尾对list进行清空呢? //需要进行清空操作么?需要,那么对targettrackerlet需要怎样进行处理呢?保留,在之后还需要进行下一阶段的相似度判断 return false;//表示不需要进行检测,可以继续进行下一次循环 } }
//looks like it works by debugging, not by running the whole programm, to remove if another version exists void ParticleContainerLC::bindOppositeWalls(int fixedDim, int fixedVal) { //LOG4CXX_DEBUG(particlelog, "start periodic"); int idx[DIM]; idx[fixedDim] = fixedVal; #if 1<DIM const int nextDim = (fixedDim+1) % DIM; #endif #if 3==DIM const int lastDim = (fixedDim+2) % DIM; #endif // iterate over wall cells #if 1<DIM for (idx[nextDim] = 0; idx[nextDim] < allCellNums[nextDim]; idx[nextDim]++) #endif #if 3==DIM for (idx[lastDim] = 0; idx[lastDim] < allCellNums[lastDim]; idx[lastDim]++) #endif { int index = calcIndex(idx, allCellNums); ParticleList *pl = allCells[index]->root; // set index of opposite boundary wall int idx_n[DIM]; for (int i = 0; i < DIM; i++) idx_n[i] = idx[i]; if (fixedVal == 0) idx_n[fixedDim] = allCellNums[fixedDim]-2; else idx_n[fixedDim] = 1; int oppositeIndex = calcIndex(idx_n, allCellNums); while (pl != NULL) { // iterate over all particles in the cell // update p for move to opposite boundary Particle& p = *pl->p; utils::Vector<double, 3>& x = p.getX(); ParticleList *cpy = pl->next; if (fixedVal == 0) { //LOG4CXX_DEBUG(particlelog, "x before (fixedVal=0) " <<allCells[calcIndex(idx, allCellNums)]->root->p->getX().toString()); x[fixedDim] += domainSize[fixedDim]; //LOG4CXX_DEBUG(particlelog, "x after (fixedVal=0) " <<allCells[calcIndex(idx, allCellNums)]->root->p->getX().toString()); //cout<<"x value:"<<cells[calcIndex(idx, cellNums)].root->p->toString()<<endl; } else { //LOG4CXX_DEBUG(particlelog, "x before (fixedVal=cellNums) " << p.getX().toString()); x[fixedDim] -= domainSize[fixedDim]; //LOG4CXX_DEBUG(particlelog, "x after (fixedVal=cellNums) " << p.getX().toString()); } // insert p into opposite boundary insertList(&allCells[oppositeIndex]->root, pl); pl = cpy; } // set own content to copy of opposite boundary cell's content //allCells[index]->root = allCells[oppositeIndex]->root; //LOG4CXX_DEBUG(particlelog, "cell finished"); //LOG4CXX_DEBUG(particlelog, "index:" << idx[0] << "," << idx[1] << "," << idx[2]); //LOG4CXX_DEBUG(particlelog, "index_n:" << idx_n[0] << "," << idx_n[1] << "," << idx_n[2]); // should also work, but quite memory consuming allCells[index]->root = NULL; // remove existing ParticleList ParticleList *pl2 = allCells[oppositeIndex]->root; while (pl2 != NULL) { Particle& p = *pl2->p; Particle *ghost = new Particle; utils::Vector<double, 3>& x = ghost->getX(); x = p.getX(); if (fixedVal == 0) x[fixedDim] -= domainSize[fixedDim]; else x[fixedDim] += domainSize[fixedDim]; ParticleList *pl_n = new ParticleList; pl_n->next = NULL; pl_n->p = ghost; insertList(&allCells[index]->root, pl_n); pl2 = pl2->next; } } //LOG4CXX_DEBUG(particlelog, "end periodic"); }
ParticleContainerLC::ParticleContainerLC(ParticleContainer* pc, Simulation *sim) { for (int i = 0; i < 3; i++) { domainSize[i] = sim->domainSize[i]; } radius = sim->cutoff; distance = sim->meshWidth; this->sim = sim; for (int i = 0; i < 6; i++) { domainBoundary[i] = sim->boundaries->getBoundary((BoundaryConds::Side)i); } for (int d = 0; d < DIM; d++) { int expansion = domainSize[d] / radius; cellNums[d] = expansion > 0 ? expansion : 1; // expansion in dimension d must be at least 1 for correct numcell() cellsSize[d] = domainSize[d] / cellNums[d]; sim->cellsSize[d] = cellsSize[d]; allCellNums[d] = cellNums[d] + 2; } #if 1==DIM allCellNums[0] = cellNums[0] + 2; #elif 2==DIM haloAllCellNums= (cellNums[0] + 2) * (cellNums[1] + 2) - cellNums[0]*cellNums[1]; #elif 3==DIM haloAllCellNums = (cellNums[0] + 2) * (cellNums[1] + 2) * (cellNums[2] + 2) - cellNums[0]*cellNums[1]*cellNums[2]; #endif cells = new Cell[numcell(cellNums)]; haloCells = new Cell[haloAllCellNums]; allCells = new Cell*[numcell(allCellNums)]; // connect allCells to cells and haloCells int i = 0; int ic[DIM], kc[DIM]; for (ic[0] = 0; ic[0] < allCellNums[0]; ic[0]++) #if 1<DIM for (ic[1] = 0; ic[1] < allCellNums[1]; ic[1]++) #endif #if 3==DIM for (ic[2] = 0; ic[2] < allCellNums[2]; ic[2]++) #endif { bool isHalo = false; for (int d = 0; d < DIM; d++) { isHalo = isHalo || ic[d] == 0 || ic[d] == allCellNums[d]-1; } if (isHalo) { haloCells[i].root = NULL; allCells[calcIndex(ic, allCellNums)] = &haloCells[i]; i++; //LOG4CXX_DEBUG(particlelog, "halo " << i << "of " << haloAllCellNums << " all:" << numcell(allCellNums) << " inner:" << numcell(cellNums)); } else { #if 1==DIM int tmp[DIM] = {ic[0]-1}; #elif 2==DIM int tmp[DIM] = {ic[0]-1, ic[1]-1}; #elif 3==DIM int tmp[DIM] = {ic[0]-1, ic[1]-1, ic[2]-1}; #endif cells[calcIndex(tmp, cellNums)].root = NULL; allCells[calcIndex(ic, allCellNums)] = &cells[calcIndex(tmp, cellNums)]; } } int count = 0; //LOG4CXX_DEBUG(particlelog, "before insert"); if (pc != NULL) { particles = pc->particles; iterator = pc->iterator; othersIterator = pc->othersIterator; pc->resetIterator(); while (pc->hasNext()) { Particle& p = pc->next(); #if 1==DIM int particleIndex[]= {p.getX()[0] / radius, 0, 0}; #elif 2==DIM int particleIndex[]= {p.getX()[0] / radius, p.getX()[1] / radius, p.getX()[2] / radius}; #elif 3==DIM int particleIndex[] = { p.getX()[0] / cellsSize[0], p.getX()[1] / cellsSize[1], p.getX()[2] / cellsSize[2] }; #endif // skip particles that don't suite into the domain //LOG4CXX_DEBUG(particlelog, "add p: " << p.getX().toString() << ", domain:" << domainSize[0] << "," << domainSize[1] << "," << domainSize[2]); bool outofbound = false; for (int d = 0; d < 3; d++) { if (particleIndex[d] >= cellNums[d] || particleIndex[d] < 0 || p.getX()[d] < 0.0 || p.getX()[d] > domainSize[d]) outofbound = true; } if (outofbound) continue; count++; ParticleList* pl = new ParticleList; pl->p = &p; pl->next = NULL; insertList((ParticleList**)&(cells[calcIndex(particleIndex, cellNums)].root), pl); //LOG4CXX_DEBUG(particlelog, "add p: " << p.getX().toString() << " to index " << particleIndex[0] << "," << particleIndex[1] << "," << particleIndex[2]); //LOG4CXX_DEBUG(particlelog, "root: " << cells[calcIndex(particleIndex, cellNums)].root->p->getX().toString()); } } LOG4CXX_DEBUG(particlelog, "grid: " << cellNums[0] << " x " << cellNums[1] << #if 3==DIM " x " << cellNums[2] << #endif ", inserted count:" << count << ", size() delivers:" << size()); }
//============================================================================== void AztecDVBR_Matrix::readAllocateInfo(FILE* infile, int*& num_nz_blocks, int*& blk_col_inds) { // //This function will read through infile and construct the lists //num_nz_blocks (which is the number of nonzero blocks per row) and //blk_col_inds (which is the block-column indices of those blocks). // //It is assumed that these two lists are empty when this function is //called. int i; if (num_nz_blocks) delete [] num_nz_blocks; if (blk_col_inds) delete [] blk_col_inds; num_nz_blocks = new int[N_update_]; //we'll use a 2-D array for constructing the set of block column indices, //because we need to keep them grouped by rows, and we aren't guaranteed //that they'll be grouped by rows in the file. int totalNumBlks = 0; int** blkColInds = new int*[N_update_]; for(i=0; i<N_update_; i++) { num_nz_blocks[i] = 0; blkColInds[i] = NULL; } int blkRows, blkCols, rows, cols; char line[256]; do { fgets(line,256,infile); } while(strchr(line,'%')); sscanf(line,"%d %d %d %d",&blkRows, &blkCols, &rows, &cols); if ((blkRows != blkCols) || (rows != cols)) messageAbort("readAllocateInfo: non-square matrix not allowed."); int br, bc, pr, pc, index; while (!feof(infile)) { do { fgets(line,256,infile); } while(strchr(line,'%')); if(feof(infile))break; sscanf(line, "%d %d %d %d", &br, &bc, &pr, &pc); if (inUpdate(br, index)) { if ((bc < 0) || bc >= blkCols) { char mesg[80]; sprintf(mesg,"readAllocateInfo: blkCols %d, 0-based col ind %d", blkCols, bc); fclose(infile); messageAbort(mesg); } insertList(bc, blkColInds[index], num_nz_blocks[index]); totalNumBlks++; } } //so we've read the whole file, now flatten the 2-D list blkColInds //into the required 1-D list blk_col_inds. blk_col_inds = new int[totalNumBlks]; int offset = 0; for(i=0; i<N_update_; i++) { for(int j=0; j<num_nz_blocks[i]; j++) { blk_col_inds[offset++] = blkColInds[i][j]; } delete [] blkColInds[i]; } delete [] blkColInds; }
MarginDialog::MarginDialog( QWidget* parent, ScribusDoc* doc ) : QDialog( parent) { setModal(true); setWindowTitle( tr( "Manage Page Properties" ) ); setWindowIcon(IconManager::instance()->loadIcon("AppIcon.png")); unitRatio = doc->unitRatio(); dialogLayout = new QVBoxLayout(this); dialogLayout->setMargin(10); dialogLayout->setSpacing(5); dsGroupBox7 = new QGroupBox(this); dsGroupBox7->setTitle( tr( "Page Size" ) ); dsGroupBox7Layout = new QGridLayout(dsGroupBox7); dsGroupBox7Layout->setAlignment( Qt::AlignTop ); dsGroupBox7Layout->setSpacing( 5 ); dsGroupBox7Layout->setMargin( 10 ); TextLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7 ); dsGroupBox7Layout->addWidget( TextLabel1, 0, 0, 1, 2 ); PageSize *ps=new PageSize(doc->currentPage()->m_pageSize); prefsPageSizeName=ps->name(); sizeQComboBox = new QComboBox(dsGroupBox7); QStringList insertList(ps->activeSizeTRList()); if (insertList.indexOf(prefsPageSizeName)==-1) insertList<<prefsPageSizeName; insertList.sort(); insertList<<CommonStrings::trCustomPageSize; sizeQComboBox->addItems(insertList); int sizeIndex = insertList.indexOf(ps->nameTR()); if (sizeIndex != -1) sizeQComboBox->setCurrentIndex(sizeIndex); else sizeQComboBox->setCurrentIndex(sizeQComboBox->count()-1); TextLabel1->setBuddy(sizeQComboBox); dsGroupBox7Layout->addWidget(sizeQComboBox, 0, 2, 1, 2); TextLabel2 = new QLabel( tr( "Orie&ntation:" ), dsGroupBox7 ); dsGroupBox7Layout->addWidget( TextLabel2, 1, 0, 1, 2 ); orientationQComboBox = new QComboBox( dsGroupBox7 ); orientationQComboBox->addItem( tr( "Portrait" ) ); orientationQComboBox->addItem( tr( "Landscape" ) ); orientationQComboBox->setEditable(false); orientationQComboBox->setCurrentIndex(doc->currentPage()->orientation() ); oldOri = doc->currentPage()->orientation(); TextLabel2->setBuddy(orientationQComboBox); dsGroupBox7Layout->addWidget( orientationQComboBox, 1, 2, 1, 2 ); widthSpinBox = new ScrSpinBox( 1, 16777215, dsGroupBox7, doc->unitIndex() ); widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7 ); widthSpinBox->setValue(doc->currentPage()->width() * doc->unitRatio()); widthQLabel->setBuddy(widthSpinBox); dsGroupBox7Layout->addWidget( widthQLabel, 2, 0 ); dsGroupBox7Layout->addWidget( widthSpinBox, 2, 1 ); heightSpinBox = new ScrSpinBox( 1, 16777215, dsGroupBox7, doc->unitIndex() ); heightSpinBox->setValue(doc->currentPage()->height() * doc->unitRatio()); heightQLabel = new QLabel( tr( "&Height:" ), dsGroupBox7 ); heightQLabel->setBuddy(heightSpinBox); dsGroupBox7Layout->addWidget( heightQLabel, 2, 2 ); dsGroupBox7Layout->addWidget( heightSpinBox, 2, 3 ); moveObjects = new QCheckBox( dsGroupBox7 ); moveObjects->setText( tr( "Move Objects with their Page" ) ); moveObjects->setChecked( true ); dsGroupBox7Layout->addWidget( moveObjects, 3, 0, 1, 4 ); Links=0; if ((doc->pagePositioning() != singlePage) && (doc->masterPageMode())) { TextLabel3 = new QLabel( tr( "Type:" ), dsGroupBox7 ); dsGroupBox7Layout->addWidget( TextLabel3, 4, 0, 1, 2 ); Links = new QComboBox( dsGroupBox7 ); QStringList::Iterator pNames; QList<PageSet> pageSet(doc->pageSets()); for(pNames = pageSet[doc->pagePositioning()].pageNames.begin(); pNames != pageSet[doc->pagePositioning()].pageNames.end(); ++pNames ) { //Links->insertItem((*pNames)); Links->addItem(CommonStrings::translatePageSetLocString((*pNames))); } Links->setEditable(false); dsGroupBox7Layout->addWidget( Links, 4, 2, 1, 2 ); if (doc->currentPage()->LeftPg == 0) Links->setCurrentIndex(Links->count()-1); else if (doc->currentPage()->LeftPg == 1) Links->setCurrentIndex(0); else Links->setCurrentIndex(doc->currentPage()->LeftPg-1); } dialogLayout->addWidget( dsGroupBox7 ); GroupRand = new MarginWidget(this, tr( "Margin Guides" ), &doc->currentPage()->initialMargins, doc->unitIndex(), false, false); GroupRand->setPageWidthHeight(doc->currentPage()->width(), doc->currentPage()->height()); GroupRand->setFacingPages(!(doc->pagePositioning() == singlePage), doc->locationOfPage(doc->currentPage()->pageNr())); GroupRand->setMarginPreset(doc->currentPage()->marginPreset); dialogLayout->addWidget( GroupRand ); groupMaster = new QGroupBox( this ); groupMaster->setTitle( tr( "Other Settings" ) ); masterLayout = new QHBoxLayout( groupMaster ); masterLayout->setSpacing( 5 ); masterLayout->setMargin( 10 ); masterPageLabel = new QLabel( groupMaster ); masterLayout->addWidget( masterPageLabel ); if (!doc->masterPageMode()) { masterPageLabel->setText( tr( "Master Page:" ) ); masterPageComboBox = new QComboBox( groupMaster ); QString Nam = doc->currentPage()->MPageNam; QString na = Nam == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : Nam, in; int cc = 0; for (QMap<QString,int>::Iterator it = doc->MasterNames.begin(); it != doc->MasterNames.end(); ++it) { in = it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key(); masterPageComboBox->addItem(in); if (in == na) masterPageComboBox->setCurrentIndex(cc); ++cc; } masterLayout->addWidget( masterPageComboBox ); pageFillColor = QColor(); } else { masterPageComboBox = NULL; masterPageLabel->setText( tr( "Page Marker Color:" ) ); QPixmap pm(100, 30); pm.fill(doc->currentPage()->getMarkColor()); pageFillColor = doc->currentPage()->getMarkColor(); pageFillColorButton = new QPushButton(this); pageFillColorButton->setText( QString::null ); pageFillColorButton->setIcon(pm); masterLayout->addWidget( pageFillColorButton ); connect(pageFillColorButton, SIGNAL(clicked()), this, SLOT(changeMarkerColor())); } dialogLayout->addWidget( groupMaster ); okCancelLayout = new QHBoxLayout; okCancelLayout->setSpacing( 5 ); okCancelLayout->setMargin( 0 ); QSpacerItem* spacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum ); okCancelLayout->addItem( spacer ); okButton = new QPushButton( CommonStrings::tr_OK, this ); okButton->setDefault( true ); okCancelLayout->addWidget(okButton); cancelButton = new QPushButton( CommonStrings::tr_Cancel, this ); cancelButton->setDefault( false ); okCancelLayout->addWidget(cancelButton); dialogLayout->addLayout( okCancelLayout ); setMaximumSize(sizeHint()); pageWidth = widthSpinBox->value() / unitRatio; pageHeight = heightSpinBox->value() / unitRatio; if (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize) { heightSpinBox->setEnabled( true ); widthSpinBox->setEnabled( true ); } else { heightSpinBox->setEnabled( false ); widthSpinBox->setEnabled( false ); } delete ps; // signals and slots connections connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); connect(orientationQComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int))); connect(sizeQComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize())); connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double))); connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double))); //tooltips sizeQComboBox->setToolTip( tr( "Size of the inserted pages, either a standard or custom size" ) ); orientationQComboBox->setToolTip( tr( "Orientation of the page(s) to be inserted" ) ); widthSpinBox->setToolTip( tr( "Width of the page(s) to be inserted" ) ); heightSpinBox->setToolTip( tr( "Height of the page(s) to be inserted" ) ); moveObjects->setToolTip( tr( "When inserting a new page between others, move objects with their current pages. This is the default action." ) ); setPageSize(); setMinimumSize(minimumSizeHint()); setMaximumSize(minimumSizeHint()); resize(minimumSizeHint()); }
ListDataModel::ListDataModel(QObject* parent) : GroupDataModel(parent) { bb::data::JsonDataAccess jda; QVariant json = jda.load(QDir::currentPath() + "/app/native/assets/contacts.json");//"/app/native/assets/employees.json" insertList(json.value<QVariantList>()); }
InsPage::InsPage( QWidget* parent, ScribusDoc* currentDoc, int currentPage, int maxPages) : QDialog( parent, 0 ) { masterPageCombos.clear(); setModal(true); setWindowTitle( tr( "Insert Page" ) ); setWindowIcon(loadIcon("AppIcon.png")); dialogLayout = new QVBoxLayout(this); dialogLayout->setSpacing( 5 ); dialogLayout->setMargin( 5 ); whereLayout = new QGridLayout(); whereLayout->setSpacing( 5 ); whereLayout->setMargin( 5 ); insCountData = new QSpinBox( this ); insCountData->setMinimum(1); insCountData->setMaximum(999); insCountData->setValue( 1 ); insCountLabel = new QLabel(tr( "&Insert" ), this ); insCountLabel->setBuddy(insCountData); whereLayout->addWidget( insCountLabel, 0, 0 ); whereLayout->addWidget( insCountData, 0, 1 ); pagesLabel = new QLabel( tr( "Page(s)" ), this); whereLayout->addWidget( pagesLabel, 0, 2 ); insWhereData = new QComboBox( this ); insWhereData->addItem( tr("before Page")); insWhereData->addItem( tr("after Page")); insWhereData->addItem( tr("at End")); insWhereData->setCurrentIndex(2); whereLayout->addWidget( insWhereData, 1, 0, 1, 2 ); insWherePageData = new QSpinBox(this); insWherePageData->setMinimum(1); insWherePageData->setMaximum(maxPages); insWherePageData->setValue( currentPage+1 ); insWherePageData->setDisabled( true ); whereLayout->addWidget( insWherePageData, 1, 2 ); whereLayout->addItem(new QSpacerItem(insCountLabel->fontMetrics().width( tr( "&Insert" )), 0), 0, 0); dialogLayout->addLayout( whereLayout ); masterPageGroup = new QGroupBox( this); masterPageGroup->setTitle( tr( "Master Pages" ) ); masterPageLayout = new QGridLayout( masterPageGroup ); masterPageLayout->setAlignment( Qt::AlignTop ); masterPageLayout->setSpacing( 5 ); masterPageLayout->setMargin( 5 ); if (currentDoc->pagePositioning() == 0) { QComboBox* pageData = new QComboBox(masterPageGroup); for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) pageData->addItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key()); if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormal)) setCurrentComboItem(pageData, CommonStrings::trMasterPageNormal); masterPageLabel = new QLabel(tr("&Master Page:"), masterPageGroup); masterPageLabel->setBuddy(pageData); masterPageLayout->addWidget( masterPageLabel, 0, 0 ); masterPageLayout->addWidget(pageData, 0, 1); masterPageCombos.append(pageData); } else { int row = 0; for (int mp = 0; mp < currentDoc->pageSets()[currentDoc->pagePositioning()].pageNames.count(); ++mp) { QComboBox* pageData = new QComboBox(masterPageGroup); // for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) // pageData->insertItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key()); if (mp == 0) { bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalLeft); for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) { if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else { if (currentDoc->MasterPages.at(it.value())->LeftPg == 1) pageData->addItem(it.key()); } } if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalLeft)) setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalLeft); } else if (mp == 1) { if (currentDoc->pageSets()[currentDoc->pagePositioning()].pageNames.count() > 2) { bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle); for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) { if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else { if ((currentDoc->MasterPages.at(it.value())->LeftPg != 0) && (currentDoc->MasterPages.at(it.value())->LeftPg != 1)) pageData->addItem(it.key()); } } if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle)) setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalMiddle); } else { bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight); for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) { if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else { if (currentDoc->MasterPages.at(it.value())->LeftPg == 0) pageData->addItem(it.key()); } } if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight)) setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight); } } else if (mp == 2) { if (currentDoc->pageSets()[currentDoc->pagePositioning()].pageNames.count() > 3) { bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle); for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) { if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else { if ((currentDoc->MasterPages.at(it.value())->LeftPg != 0) && (currentDoc->MasterPages.at(it.value())->LeftPg != 1)) pageData->addItem(it.key()); } } if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle)) setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalMiddle); } else { bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight); for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) { if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else { if (currentDoc->MasterPages.at(it.value())->LeftPg == 0) pageData->addItem(it.key()); } } if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight)) setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight); } } else if (mp == 3) { bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight); for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it) { if ((it.key() == CommonStrings::masterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam)) pageData->addItem(CommonStrings::trMasterPageNormal); else { if (currentDoc->MasterPages.at(it.value())->LeftPg == 0) pageData->addItem(it.key()); } } if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight)) setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight); } QString transLabel = currentDoc->pageSets()[currentDoc->pagePositioning()].pageNames[mp]; QLabel* pageLabel = new QLabel(CommonStrings::translatePageSetLocString(transLabel), masterPageGroup); pageLabel->setBuddy(pageData); masterPageLayout->addWidget(pageLabel, row, 0 ); masterPageLayout->addWidget(pageData, row, 1); row++; masterPageCombos.append(pageData); } } dialogLayout->addWidget(masterPageGroup); overrideMPSizingCheckBox=new QCheckBox("Override Master Page Sizing"); dialogLayout->addWidget(overrideMPSizingCheckBox); dsGroupBox7 = new QGroupBox( this ); dsGroupBox7->setTitle( tr( "Page Size" ) ); dsGroupBox7Layout = new QGridLayout( dsGroupBox7 ); dsGroupBox7Layout->setSpacing( 5 ); dsGroupBox7Layout->setMargin( 5 ); TextLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7); dsGroupBox7Layout->addWidget( TextLabel1, 0, 0); PageSize *ps=new PageSize(currentDoc->pageSize()); prefsPageSizeName=ps->name(); sizeQComboBox = new QComboBox(dsGroupBox7); QStringList insertList(ps->activeSizeTRList()); if (insertList.indexOf(prefsPageSizeName)==-1) insertList<<prefsPageSizeName; insertList.sort(); insertList<<CommonStrings::trCustomPageSize; sizeQComboBox->addItems(insertList); int sizeIndex = insertList.indexOf(ps->nameTR()); if (sizeIndex != -1) sizeQComboBox->setCurrentIndex(sizeIndex); else sizeQComboBox->setCurrentIndex(sizeQComboBox->count()-1); TextLabel1->setBuddy(sizeQComboBox); dsGroupBox7Layout->addWidget(sizeQComboBox, 0, 1, 1, 3); TextLabel2 = new QLabel( tr( "Orie&ntation:" ), dsGroupBox7); dsGroupBox7Layout->addWidget( TextLabel2, 1, 0); orientationQComboBox = new QComboBox(dsGroupBox7); orientationQComboBox->addItem( tr( "Portrait" ) ); orientationQComboBox->addItem( tr( "Landscape" ) ); orientationQComboBox->setCurrentIndex(currentDoc->pageOrientation() ); TextLabel2->setBuddy(orientationQComboBox); dsGroupBox7Layout->addWidget( orientationQComboBox, 1, 1, 1, 3 ); widthSpinBox = new ScrSpinBox( 1, 10000, dsGroupBox7, currentDoc->unitIndex() ); widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7); widthSpinBox->setValue(currentDoc->pageWidth() * currentDoc->unitRatio()); widthQLabel->setBuddy(widthSpinBox); dsGroupBox7Layout->addWidget( widthQLabel, 2, 0 ); dsGroupBox7Layout->addWidget( widthSpinBox, 2, 1 ); heightSpinBox = new ScrSpinBox( 1, 10000, dsGroupBox7, currentDoc->unitIndex() ); heightSpinBox->setValue(currentDoc->pageHeight() * currentDoc->unitRatio()); heightQLabel = new QLabel(tr( "&Height:" ), dsGroupBox7); heightQLabel->setBuddy(heightSpinBox); dsGroupBox7Layout->addWidget( heightQLabel, 2, 2 ); dsGroupBox7Layout->addWidget( heightSpinBox, 2, 3 ); moveObjects = new QCheckBox( dsGroupBox7); moveObjects->setText( tr( "Move Objects with their Page" ) ); moveObjects->setChecked( true ); dsGroupBox7Layout->addWidget( moveObjects, 3, 0, 1, 4 ); dialogLayout->addWidget( dsGroupBox7 ); dsGroupBox7->setEnabled(false); bool b=(sizeQComboBox->currentText() == CommonStrings::trCustomPageSize); heightSpinBox->setEnabled( b ); widthSpinBox->setEnabled( b ); delete ps; okCancelLayout = new QHBoxLayout; okCancelLayout->setSpacing( 5 ); okCancelLayout->setMargin( 5 ); QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); okCancelLayout->addItem( spacer ); okButton = new QPushButton( CommonStrings::tr_OK, this); okButton->setDefault( true ); okCancelLayout->addWidget( okButton ); cancelButton = new QPushButton( CommonStrings::tr_Cancel, this); okCancelLayout->addWidget( cancelButton ); dialogLayout->addLayout( okCancelLayout ); setMaximumSize(sizeHint()); unitRatio = currentDoc->unitRatio(); // signals and slots connections connect( insWhereData, SIGNAL( activated(int) ), this, SLOT( insWherePageDataDisable(int) ) ); connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); connect(orientationQComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int))); connect(sizeQComboBox, SIGNAL(activated(const QString &)), this, SLOT(setSize(const QString &))); connect(overrideMPSizingCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableSizingControls(int))); }
void radixSort ( int arr[], int digit, int size ) { int j, i, k = 0, index = 0; LinkedList *B[10]; LinkedList *pointerB[10]; for ( j = 0; j < digit; j++ ) {// We must sort the array on every digit using a stable sort algorithm. // A stable sort algorithm is an algorithm that does not changhe the place of the elements that have the same value. // This algorithm has 2 ways of being implemented. // First is by using Counting sort. This method was a little hard for me to understand so...i let it be. // The second method is by Bucket sort. This method was quite intuitive. The general method of this algorithm is // by asuming the imput values are from the interval [0, 1) and you put this values into an array lists (bucket) by a formula n*A[i]. // After the values are insterted every bucket (hehe) is sorted with Instertion sort. The final step is to concatenate the buckets and increase digit. // Our algorithm, for Radix-Sort, is a little modified and // more optimal (No sorting is required, but we must but the values back, into the array, sorted after digit j). Let's get to the actual code! //we initialize the actual buckets contorRadix = contorRadix + 3; //antetul for-ului for ( i = 0; i < 10; i++ ) { contorRadix = contorRadix + 3 + 3 + 2; //antet-ul for-ului, 3 indexari si 2 atribuiri B[i] = NULL; pointerB[i] = B[i]; } for ( i = 0; i < size; i++ ) { contorRadix = contorRadix + 3; //antetul for-ului index = (arr[i]/power(10, j))%10; contorRadix = contorRadix + 1 + 1 + 2 + 1 + 1; //am decis ca functia pow sa fie o singura operatie elementara deoarece nu tine de algoritm if ( B[index] != NULL ) {//if the starting element is not NULL we just insert the element contorRadix = contorRadix + 8; // inserarea insertList(&B[index], arr[i]); } else {//if we don't have any elements in the list we must allocate memory for it and point to the start of every list contorRadix = contorRadix + 7; //am decis sa iau inserarea intr-o lista ca fiind 3 operatii elementara:indexare, inserare contorRadix = contorRadix + 8; //inserarea, sa fie in O(1) B[index] = (LinkedList *)malloc(sizeof(LinkedList*)); B[index]->next = NULL; insertList(&B[index], arr[i]); pointerB[index] = B[index]; } } //we put in the array every element from the array of lists, sorted by digit j i = 0; k = 0; contorRadix = contorRadix + 2; // i = 0, k = 0 for ( i = 0; i < 10; i++ ) { contorRadix = contorRadix + 3; //antetul for-ului while ( pointerB[i] != NULL ) { contorRadix = contorRadix + 2; //antet-ul while-ului contorRadix = contorRadix + 9; // 4 indexari, 2 atribuiri, 2 pointari, adunare arr[k] = pointerB[i]->key; pointerB[i] = pointerB[i]->next; k++; } } } }