I don't know why separators are treated so differently than other menu objects but I am having difficulty removing separators that are side by side. Maybe someone can check my logic found below.
PreCondition: Menus and separators have already been added, the weird number that adding a separator returns is stored in a vector called separatorVec, some menu's have been hidden per the users login permissions.
What I want to do: Remove spare separators that are now stacked on top of each other so that the logged in user has no indication that menu items are missing. The code below is JUST going to check if the separator is the first visible item in them menu and remove it if it is. (it doesn't work, the code never removes a separator even if 2 separators are at the very top of the menu)
void MainScreenView::SeparatorRemovalHelper(QPopupMenu *theMenu)
{
//check the menu for separator weirdness
for (int i = 0; i < theMenu->count(); i++)
{
int currId = theMenu->idAt(i);
//loop the separatorVec and compare the funky ID's
for (int k = 0; k < separatorVec.size(); k++)
{
int sepId = separatorVec[k];
if (currId == sepId)
{
//found a separator
//make sure its not the first visible item in the menu
//work backwards from i position to test for menu
//items that are visible
bool foundVisible = false;
int j=0;
for (j = i; j != 0; j--)
{
if (theMenu->isItemVisible(j-1) == true)
{
foundVisible = true;
break;
}
}
//if didn't find a visible item from i position back
//then remove it
if (foundVisible == false)
{
theMenu->removeItem(sepId);
break;
}
}//end IF currId == sepId
}//end for int k = 0
}
}
void MainScreenView::SeparatorRemovalHelper(QPopupMenu *theMenu)
{
//check the menu for separator weirdness
for (int i = 0; i < theMenu->count(); i++)
{
int currId = theMenu->idAt(i);
//loop the separatorVec and compare the funky ID's
for (int k = 0; k < separatorVec.size(); k++)
{
int sepId = separatorVec[k];
if (currId == sepId)
{
//found a separator
//make sure its not the first visible item in the menu
//work backwards from i position to test for menu
//items that are visible
bool foundVisible = false;
int j=0;
for (j = i; j != 0; j--)
{
if (theMenu->isItemVisible(j-1) == true)
{
foundVisible = true;
break;
}
}
//if didn't find a visible item from i position back
//then remove it
if (foundVisible == false)
{
theMenu->removeItem(sepId);
break;
}
}//end IF currId == sepId
}//end for int k = 0
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks