void QgsAttributeFormEditorWidget::updateWidgets()
{
  //first update the tool buttons
  bool hasMultiEditButton = ( editPage()->layout()->indexOf( mMultiEditButton ) >= 0 );
  bool fieldReadOnly = layer()->editFormConfig().readOnly( mWidget->fieldIdx() );

  if ( hasMultiEditButton )
  {
    if ( mode() != MultiEditMode || fieldReadOnly )
    {
      editPage()->layout()->removeWidget( mMultiEditButton );
      mMultiEditButton->setParent( nullptr );
    }
  }
  else
  {
    if ( mode() == MultiEditMode && !fieldReadOnly )
    {
      editPage()->layout()->addWidget( mMultiEditButton );
    }
  }

  switch ( mode() )
  {
    case DefaultMode:
    case MultiEditMode:
    {
      stack()->setCurrentWidget( editPage() );

      editPage()->layout()->addWidget( mConstraintResultLabel );

      break;
    }

    case AggregateSearchMode:
    {
      mAggregateButton->setVisible( true );
      stack()->setCurrentWidget( searchPage() );
      break;
    }

    case SearchMode:
    {
      mAggregateButton->setVisible( false );
      stack()->setCurrentWidget( searchPage() );
      break;
    }
  }
}
/**************************************************************************************
 * Function Name: FIFO
 *
 * Description:
 *		FIFO replacement strategy
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *		PageNumber pageNum: the page number of the requested page
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Xin Su <*****@*****.**>
 *
 * History:
 *		Date        Name                                Content
 *		----------  ----------------------------------  ------------------------
 *		2015-03-15  Xin Su <*****@*****.**>         Initialization.
 **************************************************************************************/
RC FIFO(BM_BufferPool * const bm, BM_PageHandle * const page,
		PageNumber pageNum) {
	// First search the page in the queue
	RC rc = -99; // init return code
	rc = searchPage(bm, page, pageNum);

	// If find the page, then simply return RC_OK
	if (rc != RC_PAGE_NOT_FOUND) {
		return rc;
	}

	/*
	 * If the code comes here, then the Buffer Manager doesn't have the page loaded.
	 * We have to read the page from the disk and load it into BM_PageHandle.
	 */

	PageList *queue = (PageList *) bm->mgmtData;

	// If the Buffer Manager has vacancy for the requested page,
	// then read the page from the disk and append it to the tail of the PageList
	if (queue->size < bm->numPages) {
		rc = -99; // reset return code
		rc = appendPage(bm, page, pageNum);

		return rc;
	}

	/*
	 * If the code comes here, then neither the Buffer Manager has the page loaded nor has vacancy for the requested page.
	 * The size of the PageList = bm->numPages
	 * We have to replace an existing page in the Buffer Manager with the requested page.
	 */

	// Find the first removable page, starting from head
	// Set the current pointer to the head of the queue to start the traversal
	queue->current = queue->head;

	while (queue->current != queue->tail && queue->current->fixCount != 0) {
		queue->current = queue->current->next;
	}

	// After the while loop, if the current pointer comes to the tail
	// then we still need to determine if the tail's fixCount = 0
	if (queue->current == queue->tail && queue->current->fixCount != 0) {
		return RC_NO_REMOVABLE_PAGE;
	}

	/*
	 * If the code comes here, then a removable page is found, and the current pointer is pointing to it
	 */

	// Replace the removable page with the requested page
	rc = -99; // reset the return value
	rc = replacePage(bm, page, pageNum);

	return rc;
}
/**************************************************************************************
 * Function Name: unpinPage
 *
 * Description:
 *		Unpin a page
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Jie Zhou <*****@*****.**>
 *
 * History:
 *		Date        Name								Content
 *		----------  ----------------------------------	----------------------------
 *		2015-03-12  Jie Zhou <*****@*****.**>		Initialization
 *		2015-03-20	Xin Su <*****@*****.**>			Modify the logic of unpinning the requested page
 *														Add comments
 **************************************************************************************/
RC unpinPage(BM_BufferPool * const bm, BM_PageHandle * const page) {
	PageList *queue = (PageList *) bm->mgmtData;
	RC rc = -99;

	// Search the requested page
	rc = searchPage(bm, page, page->pageNum);

	if (rc != RC_OK) {
		return rc;
	}

	queue->current->fixCount--;
	return RC_OK;
}
/**************************************************************************************
 * Function Name: markDirty
 *
 * Description:
 *		Mark the dirty page
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Jie Zhou <*****@*****.**>
 *
 * History:
 *		Date        Name								Content
 *		----------  ----------------------------------	----------------------------
 *		2015-03-12  Jie Zhou <*****@*****.**>		Initialization
 *		2015-03-20	Xin Su <*****@*****.**>			Modify the logic of searching the requested page
 *														Add comments
 **************************************************************************************/
RC markDirty(BM_BufferPool * const bm, BM_PageHandle * const page) {
	PageList *queue = (PageList *) bm->mgmtData;
	RC rc = -99; // init the return code

	// Search the requested page
	rc = searchPage(bm, page, page->pageNum);

	if (rc != RC_OK) {
		return rc;
	}

	// Mark the requested page (pointed by the current pointer) dirty
	queue->current->dirtyFlag = TRUE;

	return RC_OK;
}
/**************************************************************************************
 * Function Name: unpinPage
 *
 * Description:
 *		Unpin a page
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Jie Zhou <*****@*****.**>
 *
 * History:
 *		Date        Name								Content
 *		----------  ----------------------------------	----------------------------
 *		2015-03-12  Jie Zhou <*****@*****.**>		Initialization
 *		2015-03-20	Xin Su <*****@*****.**>			Modify the logic of unpinning the requested page
 *														Add comments
 **************************************************************************************/
RC unpinPage(BM_BufferPool * const bm, BM_PageHandle * const page) {
	PageList *queue = (PageList *) bm->mgmtData;
	RC rc;

	// First search the requested page in the queue
	rc = -99;
	rc = searchPage(bm, page, page->pageNum);

	// if something unexpected error happens  or page not found, then return rc
	if (rc != RC_PAGE_FOUND) {
		return rc;
	}

	// Set statistics
	queue->current->fixCount--;
	return RC_OK;
} // unpinPage
/**************************************************************************************
 * Function Name: markDirty
 *
 * Description:
 *		Mark the requested page as dirty
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Jie Zhou <*****@*****.**>
 *
 * History:
 *		Date        Name								Content
 *		----------  ----------------------------------	----------------------------
 *		2015-03-12  Jie Zhou <*****@*****.**>		Initialization
 *		2015-03-20	Xin Su <*****@*****.**>			Modify the logic of searching the requested page
 *														Add comments
 *		2015-03-26	Xin Su <*****@*****.**>			Add thread read-write lock
 **************************************************************************************/
RC markDirty(BM_BufferPool * const bm, BM_PageHandle * const page) {
	PageList *queue = (PageList *) bm->mgmtData;
	RC rc; // init the return code

	// First search the requested page in the PageList
	rc = -99;
	rc = searchPage(bm, page, page->pageNum);

	// if something unexpected error happens or page not found, then return rc
	if (rc != RC_PAGE_FOUND) {
		return rc;
	}

	// Now the current pointer points to the requested page
	// Mark the requested page (pointed by the current pointer) dirty
	queue->current->dirtyFlag = TRUE;

	return RC_OK;
} // markDirty
/**************************************************************************************
 * Function Name: forcePage
 *
 * Description:
 *		Write the requested page back to the page file on disk
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Jie Zhou <*****@*****.**>
 *
 * History:
 *		Date        Name								Content
 *		----------  ----------------------------------	----------------------------
 *		2015-03-13  Jie Zhou <*****@*****.**>		Initialization
 *		2015-03-20	Xin Su <*****@*****.**>			Modify the logic of forcing to write the requested page back
 *														Add comments
 **************************************************************************************/
RC forcePage(BM_BufferPool * const bm, BM_PageHandle * const page) {
	PageList *queue = (PageList *) bm->mgmtData;
	RC rc = -99;

	// Search the requested page
	rc = searchPage(bm, page, page->pageNum);

	if (rc != RC_OK) {
		return rc;
	}

	// Write the requested page back to the disk
	rc = -99;
	rc = writeBlock(queue->current->page->pageNum, F_HANDLE,
			queue->current->page->data);

	if (rc != RC_OK) {
		return rc;
	}

	return RC_OK;
}
Example #8
0
void
handlePage(FILE *infile,PgInfo * pg)
{
    static char *pgBuf = 0;
    static int pgBufSize = 0;

    char *title, *body;

    if (pg->size > pgBufSize - 1) {
        if (pgBuf)
            free(pgBuf);
        pgBufSize = pg->size + 20000;
        pgBuf = (char *)malloc(pgBufSize);

        if (!pgBuf) {
            fprintf(stderr,"%s: Out of memory\n", progName);
            exit(1);
        }
    }

    fseek(infile, pg->start, 0);
    fread(pgBuf, pg->size, 1, infile);
    pgBuf[pg->size] = 0;

    splitpage(pgBuf, &title, &body);
    /*untexbuf(title);*/
    untexbuf(body);

#ifdef DEBUG
    printf("-------------- %s -------------\n%s", pg->name, pgBuf);
    printf("============== %s =============\n", title);
    printf("%s", body);
#endif

    searchPage(pg->name, title, body);

}
/**************************************************************************************
 * Function Name: CLOCK
 *
 * Description:
 *		CLOCK replacement strategy
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *		PageNumber pageNum: the page number of the requested page
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Xin Su <*****@*****.**>
 *
 * History:
 *		Date        Name                                Content
 *		----------  ----------------------------------  ------------------------
 *		2015-03-15  Xin Su <*****@*****.**>         Initialization.
 **************************************************************************************/
RC CLOCK(BM_BufferPool * const bm, BM_PageHandle * const page,
		PageNumber pageNum) {
	PageList *queue = (PageList *) bm->mgmtData;

	// First search the page in the queue.
	RC rc = -99; // init return code
	rc = searchPage(bm, page, pageNum);

	// if find the page, set the current page's clockFlag to TRUE
	// else if other errors happen, return rc
	if (rc == RC_OK) {
		queue->current->clockFlag = TRUE;
		return rc;
	} else if (rc != RC_PAGE_NOT_FOUND) {
		return rc;
	}

	/*
	 * If the code comes here, then the Buffer Manager doesn't have the page loaded.
	 * We have to read the page from the disk and load it into BM_PageHandle.
	 */

	// If the Buffer Manager has vacancy for the requested page,
	// then read the page from the disk and append it to the tail of the PageList
	if (queue->size < bm->numPages) {
		rc = -99; // reset return code
		rc = appendPage(bm, page, pageNum);

		if (rc == RC_OK) {
			// Set the clock pointer to the next to the current pointer
			// if the PageList is not full, set the clock pointer to the next to the current pointer
			// else, set the clock pointer to the head
			if (queue->size < bm->numPages) {
				queue->clock = queue->current->next;
			} else if (queue->size == bm->numPages) {
				queue->clock = queue->head;
			}
		}

		return rc;
	}

	/*
	 * If the code comes here, then neither the Buffer Manager has the page loaded nor has vacancy for the requested page.
	 * The size of the PageList = bm->numPages
	 * We have to replace an existing page in the Buffer Manager with the requested page.
	 */

	// Logic of CLOCK replacement strategy
	// Now the current points to should point to the page that was requested last time
	while (queue->clock->clockFlag != FALSE) {
		queue->clock->clockFlag = FALSE;

		if (queue->clock == queue->tail) {
			queue->clock = queue->head;
		} else {
			queue->clock = queue->clock->next;
		}
	}

	// We find the first PageFrame whose clockFlag is FALSE
	// Set the current pointer to the clock pointer
	queue->current = queue->clock;
	/*RC*/rc = -99;// do not need to redefine RC
	rc = replacePage(bm, page, pageNum);

	if (rc == RC_OK) {
		// After the replacement of the requested page, set its clockFlag to TRUE
		queue->clock->clockFlag = TRUE;

		// TO DO - Whether we need to set the clock pointer to the next to the current pointer?
		if (queue->clock == queue->tail) {
			queue->clock = queue->head;
		} else {
			queue->clock = queue->clock->next;
		}
	}

	return rc;
}
/**************************************************************************************
 * Function Name: CLOCK
 *
 * Description:
 *		CLOCK replacement strategy
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *		PageNumber pageNum: the page number of the requested page
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Xin Su <*****@*****.**>
 *
 * History:
 *		Date        Name                                Content
 *		----------  ----------------------------------  ------------------------
 *		2015-03-15  Xin Su <*****@*****.**>         Initialization
 **************************************************************************************/
RC CLOCK(BM_BufferPool * const bm, BM_PageHandle * const page,
		PageNumber pageNum) {
	PageList *queue = (PageList *) bm->mgmtData;
	RC rc; // init return code

	// First search the page in the PageList
	printf("searchPage: Page-%d\n", pageNum);
	rc = -99;
	rc = searchPage(bm, page, pageNum);

	// if find the page, set the current page's clockFlag to TRUE
	// else if other errors happen, return rc
	if (rc == RC_PAGE_FOUND) {
		queue->current->fixCount++;
		queue->current->clockFlag = TRUE;
		printf("Page-%d found\n", pageNum);

		return rc;
	} else if (rc != RC_PAGE_NOT_FOUND) {
		return rc;
	}
	printf("Page-%d not found\n", pageNum);

	/*
	 * If the code comes here, then the Buffer Manager doesn't have the page loaded.
	 * We have to read the page from the disk and load it into BM_PageHandle.
	 */

	// if the Buffer Manager has vacancy for the requested page,
	// then read the page from the disk and append it to the next to the tail of the PageList
	if (queue->size < bm->numPages) {
		printf("appendPage: Page-%d\n", pageNum);
		rc = -99; // reset return code
		rc = appendPage(bm, page, pageNum);

		// if the PageList is not full, set the clock pointer to the next to the current pointer
		// else, now the current pointer points to the tail, then set the clock pointer points back to the head
		if (rc == RC_OK) {
			if (queue->size < bm->numPages) {
				queue->clock = queue->current->next;
			} else if (queue->size == bm->numPages) {
				queue->clock = queue->head;
			}

			printf("Page-%d appended\n", pageNum);
		}

		return rc;
	}

	/*
	 * If the code comes here, then neither the Buffer Manager has the page loaded nor vacancy for the requested page
	 * Now the PageList is full: the size of the PageList = bm->numPages
	 * We have to replace an existing page in the Buffer Manager with the requested page
	 */

	// Logic of CLOCK replacement strategy
	// Now the current pointer points to the page that was requested last time,
	// and the clock pointer points to the next to the current pointer (or back to the head if the current pointers points to the tail)
	// Find the first page with clockFlag = TRUE and fixCount = 0
	while (queue->clock->clockFlag == TRUE || queue->clock->fixCount != 0
			|| queue->clock->numReadIO != 0 || queue->clock->numWriteIO != 0) {
		queue->clock->clockFlag = FALSE;

		// Into the while loop means this page does not fit the requirement of the removable page
		// Move the clock pointer to the next. If it points to the tail, move it back to the head
		if (queue->clock == queue->tail) {
			queue->clock = queue->head;
		} else {
			queue->clock = queue->clock->next;
		}
	}

	// We find the first PageFrame whose clockFlag = FALSE and fixCount = 0
	// Set the current pointer to the clock pointer, so that we can call replacePage
	queue->current = queue->clock;

	// Replace the removable page with the requested page
	printf("replacePage: Page-%d\n", pageNum);
	rc = -99;
	rc = replacePage(bm, page, pageNum);

	if (rc == RC_OK) {
		// After the replacement of the requested page, set its clockFlag to TRUE
		queue->clock->clockFlag = TRUE;

		// Set the clock pointer to the next to the current pointer
		if (queue->clock == queue->tail) {
			queue->clock = queue->head;
		} else {
			queue->clock = queue->clock->next;
		}

		printf("Page-%d replaced\n", pageNum);
	}

	return rc;
} // CLOCK
/**************************************************************************************
 * Function Name: FIFO
 *
 * Description:
 *		FIFO replacement strategy
 *
 * Parameters:
 *		BM_BufferPool * const bm: Buffer Pool Handler
 *		BM_PageHandle * const page: Buffer Page Handler
 *		PageNumber pageNum: the page number of the requested page
 *
 * Return:
 *		RC: return code
 *
 * Author:
 *		Xin Su <*****@*****.**>
 *
 * History:
 *		Date        Name                                Content
 *		----------  ----------------------------------  ------------------------
 *		2015-03-15  Xin Su <*****@*****.**>         Initialization.
 **************************************************************************************/
RC FIFO(BM_BufferPool * const bm, BM_PageHandle * const page,
		PageNumber pageNum) {
	PageList *queue = (PageList *) bm->mgmtData;
	RC rc; // init return code

	// First search the requested page in the PageList
	printf("searchPage: Page-%d\n", pageNum);
	rc = -99;
	rc = searchPage(bm, page, pageNum);

	// First search the requested page in the queue
	// if the requested page is found, then set statistics and return rc (RC_PAGE_FOUND)
	// else if something unexpected error happens, then return rc
	if (rc == RC_PAGE_FOUND) {
		queue->current->fixCount++;
		printf("Page-%d found\n", pageNum);

		return rc;
	} else if (rc != RC_PAGE_NOT_FOUND) {
		return rc;
	}
	printf("Page-%d not found\n", pageNum);

	/*
	 * If the code comes here, then the Buffer Manager doesn't have the requested page
	 * We have to read the page from the disk and load it into BM_PageHandle.
	 */

	// if the Buffer Manager has vacancy for the requested page,
	// then read the page from the disk and append it to the next of the tail of the PageList
	if (queue->size < bm->numPages) {
		printf("appendPage: Page-%d\n", pageNum);
		rc = -99; // reset return code
		rc = appendPage(bm, page, pageNum);

		if (rc == RC_OK) {
			printf("Page-%d appended\n", pageNum);
		}

		return rc;
	}

	/*
	 * If the code comes here, then neither the Buffer Manager has the requested page loaded nor vacancy for the requested page
	 * Now the PageList is full: the size of the PageList = bm->numPages
	 * We have to replace an existing page in the Buffer Manager with the requested page
	 */

	// Find the first removable page, starting from head
	// Set the current pointer to the head of the queue to start the traversal
	queue->current = queue->head;

	// Find the first page with fixCount = 0
	while (queue->current != queue->tail
			&& (queue->current->fixCount != 0 || queue->current->numReadIO != 0
					|| queue->current->numWriteIO != 0)) {
		queue->current = queue->current->next;
	}

	// After the while loop, if the current pointer comes to the tail,
	// then we still need to determine if the tail's fixCount = 0
	if (queue->current == queue->tail
			&& (queue->current->fixCount != 0 || queue->current->numReadIO != 0
					|| queue->current->numWriteIO != 0)) {
		return RC_NO_REMOVABLE_PAGE;
	}

	/*
	 * If the code comes here, then a removable page is found
	 * The current pointer is pointing to it
	 */

	// Replace the removable page with the requested page
	printf("replacePage: Page-%d\n", pageNum);
	rc = -99; // reset the return value
	rc = replacePage(bm, page, pageNum);

	// if replacePage completes without error and the requested page is not in the tail spot
	// then move it to the tail of the PageList
	if (rc == RC_OK && queue->current != queue->tail) {
		// Remove the current PageFrame
		// The steps of the remove are different depending on if the requested page is the head or not
		if (queue->current == queue->head) {
			queue->head = queue->head->next;
			queue->current->next->previous = NULL;
		} else {
			queue->current->previous->next = queue->current->next;
			queue->current->next->previous = queue->current->previous;
		}

		// Add the requested page to the tail of the PageList
		// step 1 - connect tail and current
		queue->current->previous = queue->tail;
		queue->tail->next = queue->current;

		// step 2 - set current's next
		queue->current->next = NULL;

		// step 3 - set tail
		queue->tail = queue->tail->next;

		printf("Page-%d replaced\n", pageNum);

		// Now the current pointer still points to the requested page
	}

	return rc;
} // FIFO
Example #12
0
void WebTab::startSearch() {
  if (SCUT_SEARCH_PAGE == m_search_type) searchPage(); 
  else searchOnline();
}