From 43874efc17dbd203b030095ddc83fe5c9d37249b Mon Sep 17 00:00:00 2001 From: zeljko Date: Sat, 10 Dec 2011 08:22:53 +0000 Subject: [PATCH] Qt: fixed combobox itemindex when list contain duplicates. issue #20863 git-svn-id: trunk@34079 - --- lcl/interfaces/qt/qtwidgets.pas | 6 ++++++ lcl/interfaces/qt/qtwsstdctrls.pp | 25 +++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index b511345fc3..09b6120d5c 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -911,6 +911,7 @@ type procedure ClearItems; procedure setBorder(const ABorder: Boolean); function currentIndex: Integer; + function findText(AText: WideString): Integer; function getDroppedDown: Boolean; function getEditable: Boolean; function getMaxVisibleItems: Integer; @@ -8503,6 +8504,11 @@ begin Result := QComboBox_currentIndex(QComboBoxH(Widget)); end; +function TQtComboBox.findText(AText: WideString): Integer; +begin + Result := QComboBox_findText(QComboBoxH(Widget), @AText); +end; + function TQtComboBox.getDroppedDown: Boolean; begin Result := QWidget_isVisible(QComboBox_view(QComboBoxH(Widget))); diff --git a/lcl/interfaces/qt/qtwsstdctrls.pp b/lcl/interfaces/qt/qtwsstdctrls.pp index 645061097e..8bafddf742 100644 --- a/lcl/interfaces/qt/qtwsstdctrls.pp +++ b/lcl/interfaces/qt/qtwsstdctrls.pp @@ -1352,8 +1352,8 @@ var QtComboBox: TQtComboBox; begin Result := False; - if not ACustomComboBox.HandleAllocated then - exit; + if not WSCheckHandleAllocated(ACustomComboBox, 'GetDroppedDown') then + Exit; QtComboBox := TQtComboBox(ACustomComboBox.Handle); Result := QtComboBox.getDroppedDown; end; @@ -1367,8 +1367,6 @@ class function TQtWSCustomComboBox.GetItemIndex( const ACustomComboBox: TCustomComboBox): integer; var QtComboBox: TQtComboBox; - WStr: WideString; - i: Integer; begin Result := -1; if not WSCheckHandleAllocated(ACustomComboBox, 'GetItemIndex') then @@ -1376,11 +1374,12 @@ begin QtComboBox := TQtComboBox(ACustomComboBox.Handle); if QtComboBox.getEditable then begin - WStr := QtComboBox.getText; - i := QComboBox_findText(QComboBoxH(QtComboBox.Widget), @WStr); - Result := i; + Result := QtComboBox.findText(QtComboBox.getText); + if Result = -1 then + exit; + Result := QtComboBox.currentIndex; end else - Result := TQtComboBox(ACustomComboBox.Handle).currentIndex; + Result := QtComboBox.currentIndex; end; class function TQtWSCustomComboBox.GetMaxLength( @@ -1388,6 +1387,8 @@ class function TQtWSCustomComboBox.GetMaxLength( var LineEdit: TQtLineEdit; begin + if not WSCheckHandleAllocated(ACustomComboBox, 'GetMaxLength') then + Exit; LineEdit := TQtComboBox(ACustomComboBox.Handle).LineEdit; if LineEdit <> nil then begin @@ -1484,6 +1485,8 @@ end; class procedure TQtWSCustomComboBox.SetDropDownCount( const ACustomComboBox: TCustomComboBox; NewCount: Integer); begin + if not WSCheckHandleAllocated(ACustomComboBox, 'SetDropDownCount') then + Exit; TQtComboBox(ACustomComboBox.Handle).setMaxVisibleItems(NewCount); end; @@ -1492,6 +1495,8 @@ class procedure TQtWSCustomComboBox.SetDroppedDown( var QtComboBox: TQtComboBox; begin + if not WSCheckHandleAllocated(ACustomComboBox, 'SetDroppedDown') then + Exit; QtComboBox := TQtComboBox(ACustomComboBox.Handle); QtComboBox.setDroppedDown(ADroppedDown); end; @@ -1503,6 +1508,8 @@ end; ------------------------------------------------------------------------------} class procedure TQtWSCustomComboBox.SetItemIndex(const ACustomComboBox: TCustomComboBox; NewIndex: integer); begin + if not WSCheckHandleAllocated(ACustomComboBox, 'SetItemIndex') then + Exit; TQtComboBox(ACustomComboBox.Handle).setCurrentIndex(NewIndex); end; @@ -1548,6 +1555,8 @@ class function TQtWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboB var ComboBox: TQtComboBox; begin + if not WSCheckHandleAllocated(ACustomComboBox, 'GetItems') then + Exit; ComboBox := TQtComboBox(ACustomComboBox.Handle); if not Assigned(ComboBox.FList) then begin