void ChoroidTab::SetSortMenu () { auto sortGroup = new QActionGroup (this); SortMenu_ = new QMenu; auto byName = SortMenu_->addAction (tr ("By name"), this, SLOT (sortByName ())); byName->setCheckable (true); byName->setChecked (true); sortGroup->addAction (byName); auto byDate = SortMenu_->addAction (tr ("By date"), this, SLOT (sortByDate ())); byDate->setCheckable (true); sortGroup->addAction (byDate); auto bySize = SortMenu_->addAction (tr ("By size"), this, SLOT (sortBySize ())); bySize->setCheckable (true); sortGroup->addAction (bySize); auto byNumber = SortMenu_->addAction (tr ("By number"), this, SLOT (sortByNumber ())); byNumber->setCheckable (true); sortGroup->addAction (byNumber); sortByName (); auto sortModeButton = new QToolButton (); sortModeButton->setIcon (Proxy_->GetIcon ("view-sort-ascending")); sortModeButton->setText (tr ("Sort mode")); sortModeButton->setPopupMode (QToolButton::InstantPopup); sortModeButton->setMenu (SortMenu_); Bar_->addWidget (sortModeButton); }
int main() { int n; int i; scanf("%d", &n); // input the size of table int table[1000]; for (i = 0; i < n; i++) scanf("%d", table + i); // input the information in the table Element element[1000]; int elementCount = 0; for (i = 0; i < n; i++) if (table[i] < 0) { element[elementCount].position = i; element[elementCount].number = table[i]; element[elementCount].hashposition = table[i] % n; elementCount++; /* saving and calculate the informations of numbers in the table */ } sortByNumber(element, elementCount); // sort the Element array by the element's number int simulatetable[1000]; for (i = 0; i < n; i++) simulatetable[i] = -1; // initial the simulative hash table for algorithm int disjointSet[1000]; for (i = 0; i < n; i++) disjointSet[i] = -1; // initial the disjoint set data structure int flag = 0; // flag means this progorm has outputed or not while (elementCount) { int i; for (i = 0; i < elementCount; i++) if (checkInserted(element[i].hashposition, element[i].position, simulatetable, n, disjointSet)) // checkInserted return ture when element[i] can be insterted { if (flag) printf(" "); // this part is for outputing format else flag = 1; printf("%d", element[i].number); // ouput the number current inserting simulatetable[element[i].position] = element[i].number; // inserted element[i] to the simulative hash table int insertedPosition = element[i].position; // saving the current inserting position int pre = insertedPosition - 1; if (pre < 0) pre += n; // calculate the adjacent position's index int post = insertedPosition + 1; if (post >= n) post -= n; // calculate the adjacent position's index if (simulatetable[pre] != -1) uni(pre, insertedPosition, disjointSet); if (simulatetable[post] != -1) uni(post, insertedPosition, disjointSet); /* union the current inserting posision's set to adjacent posision's set when the adjacent positions in the table was inserted */ int j; for (j = i; j < elementCount - 1; j++) // iterating the element array { element[j].hashposition = element[j + 1].hashposition; element[j].position = element[j + 1].position; element[j].number = element[j + 1].number; /* save the information of element[j + 1] to element[j] */ } elementCount--; /* remove element[i] from element array */ break; } } printf("\n"); return 0; }
context_menu->addSeparator(); hide_action = context_menu->addAction({}, this, SLOT(setSelectedSymbolVisibility(bool))); hide_action->setCheckable(true); protect_action = context_menu->addAction({}, this, SLOT(setSelectedSymbolProtection(bool))); protect_action->setCheckable(true); context_menu->addSeparator(); QMenu* select_menu = new QMenu(tr("Select symbols"), context_menu); select_menu->addAction(tr("Select all"), this, SLOT(selectAll())); select_menu->addAction(tr("Select unused"), this, SLOT(selectUnused())); select_menu->addSeparator(); select_menu->addAction(tr("Invert selection"), this, SLOT(invertSelection())); context_menu->addMenu(select_menu); QMenu* sort_menu = new QMenu(tr("Sort symbols"), context_menu); sort_menu->addAction(tr("Sort by number"), this, SLOT(sortByNumber())); sort_menu->addAction(tr("Sort by primary color"), this, SLOT(sortByColor())); sort_menu->addAction(tr("Sort by primary color priority"), this, SLOT(sortByColorPriority())); sort_manual_action = sort_menu->addAction(tr("Enable drag and drop")); sort_manual_action->setCheckable(true); context_menu->addMenu(sort_menu); connect(map, &Map::colorDeleted, this, QOverload<>::of(&QWidget::update)); connect(map, &Map::symbolAdded, this, &SymbolRenderWidget::updateAll); connect(map, &Map::symbolDeleted, this, &SymbolRenderWidget::symbolDeleted); connect(map, &Map::symbolChanged, this, &SymbolRenderWidget::symbolChanged); connect(map, &Map::symbolIconChanged, this, &SymbolRenderWidget::updateSingleIcon); connect(map, &Map::symbolIconZoomChanged, this, &SymbolRenderWidget::updateAll); connect(&Settings::getInstance(), &Settings::settingsChanged, this, &SymbolRenderWidget::settingsChanged); }