fixed auto-switching bug in GxsIdChooser

This commit is contained in:
csoler 2019-01-11 22:13:48 +01:00
parent 266edf06aa
commit 396d58da58
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
2 changed files with 27 additions and 10 deletions

View File

@ -128,10 +128,6 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
if (!chooser)
return;
int current_index = chooser->currentIndex();
QString current_id = (current_index >= 0)? chooser->itemData(current_index).toString() : "" ;
// this prevents the objects that depend on what's in the combo-box to activate and
// perform any change.Only user-changes should cause this.
chooser->blockSignals(true) ;
@ -187,15 +183,29 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
chooser->model()->sort(0);
// now restore the current item. Problem is, we cannot use the ID position because it may have changed.
if(current_id != "")
#ifdef IDCHOOSER_DEBUG
std::cerr << "GxsIdChooser: default ID = " << chooser->defaultId() << std::endl;
#endif
if(!chooser->defaultId().isNull())
{
for(int indx=0;indx<chooser->count();++indx)
if(chooser->itemData(indx).toString() == current_id)
if(RsGxsId(chooser->itemData(indx).toString().toStdString()) == chooser->defaultId())
{
chooser->setCurrentIndex(indx);
std::cerr << "GxsIdChooser-003" << (void*)chooser << " setting current index to " << indx << std::endl;
#ifdef IDCHOOSER_DEBUG
std::cerr << "GxsIdChooser-003 " << (void*)chooser << " setting current index to " << indx << " because it has ID=" << chooser->defaultId() << std::endl;
#endif
break;
}
}
else
{
RsGxsId id;
GxsIdChooser::ChosenId_Ret cid = chooser->getChosenId(id) ;
if(cid == GxsIdChooser::UnKnowId || cid == GxsIdChooser::KnowId)
chooser->setDefaultId(id) ;
}
chooser->blockSignals(false) ;
}
@ -395,6 +405,11 @@ void GxsIdChooser::myCurrentIndexChanged(int index)
} else {
setToolTip("");
}
QVariant var = itemData(index);
RsGxsId gxsId(var.toString().toStdString());
if(!gxsId.isNull())
mDefaultId = gxsId;
}
void GxsIdChooser::indexActivated(int index)

View File

@ -50,15 +50,17 @@ public:
enum ChosenId_Ret {None, KnowId, UnKnowId, NoId} ;
void loadIds(uint32_t chooserFlags, const RsGxsId &defId);
void setDefaultId(const RsGxsId &defId);
const RsGxsId defaultId() const { return mDefaultId ; }
bool setChosenId(const RsGxsId &gxsId);
ChosenId_Ret getChosenId(RsGxsId &gxsId);
void setEntryEnabled(int index, bool enabled);
void setIdConstraintSet(const std::set<RsGxsId>& s) ;
bool isInConstraintSet(const RsGxsId& id) const ;
void setIdConstraintSet(const std::set<RsGxsId>& s) ;
bool isInConstraintSet(const RsGxsId& id) const ;
uint32_t countEnabledEntries() const ;
signals: