Skip to content

Commit

Permalink
alway use dynamic_cast to cast WindowControl* to derived class
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotl committed Apr 9, 2024
1 parent 0ff7bc1 commit a464835
Show file tree
Hide file tree
Showing 63 changed files with 1,057 additions and 1,047 deletions.
10 changes: 10 additions & 0 deletions Common/Header/WindowControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,16 @@ class WindowControl : public WndCtrlBase {

WindowControl *FindByName(const TCHAR *Name);

template<typename TypeT>
std::enable_if_t<std::is_base_of_v<WindowControl, TypeT>, TypeT*>
FindChild(const TCHAR *Name) {
WindowControl* pWnd = FindByName(Name);
auto pTypeT = dynamic_cast<TypeT*>(pWnd);
assert(pWnd == pTypeT);
return pTypeT;
}


void ForEachChild(std::function<void(WindowControl*)> visitor);

protected:
Expand Down
4 changes: 2 additions & 2 deletions Common/Source/Devices/devBlueFlyVario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ namespace dlgBlueFlyConfig {



WndProperty* pWnd = (WndProperty*)wfDlg->FindByName(utf8_to_tstring(Param.Code()).c_str());
WndProperty* pWnd = wfDlg->FindChild<WndProperty>(utf8_to_tstring(Param.Code()).c_str());
if(pWnd) {
DataField* pData = pWnd->GetDataField();
if(pData) {
Expand Down Expand Up @@ -401,7 +401,7 @@ namespace dlgBlueFlyConfig {
}

// Init Enum WndProperty
WndProperty* pWnd = (WndProperty*)wfDlg->FindByName(_T("BOM"));
WndProperty* pWnd = wfDlg->FindChild<WndProperty>(_T("BOM"));
if(pWnd) {
DataField* pData = pWnd->GetDataField();
if(pData) {
Expand Down
28 changes: 14 additions & 14 deletions Common/Source/Devices/devCProbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,19 @@ BOOL CDevCProbe::Config(DeviceDescriptor_t* d){

WndButton *wBt = NULL;

wBt = (WndButton *)wf->FindByName(TEXT("cmdClose"));
wBt = wf->FindChild<WndButton>(TEXT("cmdClose"));
if(wBt){
wBt->SetOnClickNotify(OnCloseClicked);
}
wBt = (WndButton *)wf->FindByName(TEXT("cmdSetCompassCal"));
wBt = wf->FindChild<WndButton>(TEXT("cmdSetCompassCal"));
if(wBt){
wBt->SetOnClickNotify(OnCompassCalClicked);
}
wBt = (WndButton *)wf->FindByName(TEXT("cmdSetCalGyro"));
wBt = wf->FindChild<WndButton>(TEXT("cmdSetCalGyro"));
if(wBt){
wBt->SetOnClickNotify(OnCalGyroClicked);
}
wBt = (WndButton *)wf->FindByName(TEXT("cmdZeroDeltaPress"));
wBt = wf->FindChild<WndButton>(TEXT("cmdZeroDeltaPress"));
if(wBt){
wBt->SetOnClickNotify(OnZeroDeltaPressClicked);
}
Expand Down Expand Up @@ -440,57 +440,57 @@ void CDevCProbe::Update(WndForm* pWnd) {
pWnd->SetCaption(Temp);

WndProperty* wp;
wp = (WndProperty*)pWnd->FindByName(TEXT("prpPitch"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpPitch"));
if(wp){
_stprintf(Temp, TEXT("%.2f%s"), _INFO.Pitch, MsgToken<2179>());
wp->SetText(Temp);
}
wp = (WndProperty*)pWnd->FindByName(TEXT("prpHeading"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpHeading"));
if(wp){
_stprintf(Temp, TEXT("%.2f%s"), _INFO.MagneticHeading, MsgToken<2179>());
wp->SetText(Temp);
}
wp = (WndProperty*)pWnd->FindByName(TEXT("prpRoll"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpRoll"));
if(wp){
_stprintf(Temp, TEXT("%.2f%s"), _INFO.Roll, MsgToken<2179>());
wp->SetText(Temp);
}

wp = (WndProperty*)pWnd->FindByName(TEXT("prpGx"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpGx"));
if(wp){
_stprintf(Temp, TEXT("%.2f"), _INFO.AccelX);
wp->SetText(Temp);
}
wp = (WndProperty*)pWnd->FindByName(TEXT("prpGy"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpGy"));
if(wp){
_stprintf(Temp, TEXT("%.2f"), _INFO.AccelY);
wp->SetText(Temp);
}
wp = (WndProperty*)pWnd->FindByName(TEXT("prpGz"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpGz"));
if(wp){
_stprintf(Temp, TEXT("%.2f"), _INFO.AccelZ);
wp->SetText(Temp);
}

wp = (WndProperty*)pWnd->FindByName(TEXT("prpTemp"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpTemp"));
if(wp){
_stprintf(Temp, TEXT("%.2f %sC"), _INFO.OutsideAirTemperature, MsgToken<2179>());
wp->SetText(Temp);
}
wp = (WndProperty*)pWnd->FindByName(TEXT("prpRh"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpRh"));
if(wp){
_stprintf(Temp, TEXT("%.2f %%"), _INFO.RelativeHumidity);
wp->SetText(Temp);
}
wp = (WndProperty*)pWnd->FindByName(TEXT("prpDeltaPress"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpDeltaPress"));
if(wp){
LockDeviceData();
_stprintf(Temp, TEXT("%.2f Pa"), m_delta_press);
UnlockDeviceData();

wp->SetText(Temp);
}
wp = (WndProperty*)pWnd->FindByName(TEXT("prpAbsPress"));
wp = pWnd->FindChild<WndProperty>(TEXT("prpAbsPress"));
if(wp){
LockDeviceData();
_stprintf(Temp, TEXT("%.2f hPa"), m_abs_press/100.);
Expand Down
8 changes: 4 additions & 4 deletions Common/Source/Devices/devFlarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,24 @@ BOOL CDevFlarm::Config(DeviceDescriptor_t* d){

WndButton *wBt = NULL;

wBt = (WndButton *)wf->FindByName(TEXT("cmdClose"));
wBt = wf->FindChild<WndButton>(TEXT("cmdClose"));
if(wBt){
wBt->SetOnClickNotify(OnCloseClicked);
}


wBt = (WndButton *)wf->FindByName(TEXT("cmdIGCDownload"));
wBt = wf->FindChild<WndButton>(TEXT("cmdIGCDownload"));
if(wBt){
wBt->SetOnClickNotify(OnIGCDownloadClicked);
}

wBt = (WndButton *)wf->FindByName(TEXT("cmdFlarmReboot"));
wBt = wf->FindChild<WndButton>(TEXT("cmdFlarmReboot"));
if(wBt){
wBt->SetOnClickNotify(OnRebootClicked);
}
/*
WndProperty* wp;
wp = (WndProperty*)wf->FindByName(TEXT("prpFlarmId"));
wp = wf->FindChild<WndProperty>(TEXT("prpFlarmId"));
if (wp) {
wp->GetDataField()->SetAsString(_T("DD222"));
Expand Down
Loading

0 comments on commit a464835

Please sign in to comment.