Skip to content

Commit

Permalink
*Fix: Visible column could be added twice
Browse files Browse the repository at this point in the history
*Fix: When adding column to visible columns selection is moved to nearest visible item.
  • Loading branch information
iddekingej committed Sep 12, 2016
1 parent efd941d commit a8b51ea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
38 changes: 35 additions & 3 deletions gui/fieldconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,49 @@ void TFieldsConfig::removeLabel()
enableRemoveButton();
}

/*
* When field is selected in ui.fieldsAvailable and moved to the visible field
* The field is hidden in ui.fieldsAvailable and the 'next' field in fieldsAvailable must be selected
* Find first nearest visible row in ui.fieldsAvailable relative to index p_index
* first look downward and thant up
*/

int TFieldsConfig::getFAVisibleRow(int p_index)
{
int l_cnt=p_index+1;
while(l_cnt<ui.fieldsAvailable->model()->rowCount()){
if(!ui.fieldsAvailable->isRowHidden(l_cnt)) return l_cnt;
l_cnt++;
}
l_cnt=p_index-1;
while(l_cnt>=0){
if(!ui.fieldsAvailable->isRowHidden(l_cnt)) return l_cnt;
l_cnt--;
}
return -1;
}

void TFieldsConfig::addLabel()
{
QModelIndexList l_list=ui.fieldsAvailable->selectionModel()->selectedIndexes();
QListIterator<QModelIndex> l_iter=QListIterator<QModelIndex>(l_list);
QModelIndex l_item;
QStandardItem *l_itemSource;
QModelIndex l_newSelection;

if(l_iter.hasNext()){
l_item=l_iter.next();
if(l_list.size()>0){
l_item=l_list[0];

ui.fieldsAvailable->setRowHidden(l_item.row(),true);
int l_row=l_item.row();
ui.fieldsAvailable->clearSelection();
int l_newIndex=getFAVisibleRow(l_row);
if(l_newIndex>=0){
l_newSelection=ui.fieldsAvailable->model()->index(l_newIndex,0);
if(l_newSelection.isValid()){
ui.fieldsAvailable->selectionModel()->select(l_newSelection,QItemSelectionModel::Select);
}
}
l_itemSource=modelAvailable->item(l_item.row());
modelSelected->appendRow(l_itemSource->clone());
l_newSelection=modelSelected->index(modelSelected->rowCount()-1,0);
Expand Down
3 changes: 2 additions & 1 deletion gui/fieldconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ private slots:
void enableRemoveButton();
void fillAvailableList();
void fillSelectedList();
int getFAVisibleRow(int p_index);
public:
TFieldsConfig();
~TFieldsConfig();
}
;

#endif
#endif

0 comments on commit a8b51ea

Please sign in to comment.