TListView/pl

From Free Pascal wiki
Revision as of 01:03, 13 October 2021 by Slawek (talk | contribs) (→‎Sorting: tłumaczenie na j. polski)
Jump to navigationJump to search

English (en) français (fr) polski (pl) русский (ru)

TListView tlistview.png jest wizualnym komponentem na zakładce Common Controls Palety Komponentów, który zapewnia widok listy powiązanych z nim elementów. Elementy mogą być reprezentowane przez jeden z zestawów ikon powiązanych z TImageList: SmallImages, LargeImages i StateImages.

Uwagi

  • GetNextItem() wymaga podania StartItem. Jest to niezgodne z GetNextItem() Delphi, gdzie parametr StartItem może mieć wartość nil, co spowoduje wykonanie wyszukiwania od względnego (sterowanego kierunkiem) startu.

Sorting

TODO: dodać opis, w jaki sposób OwnerData wpływa na sortowanie

Sortowanie jest (zazwyczaj) stosowane podczas korzystania z vsReport ViewStyle, ponieważ jest oparte na kolumnach (z wymaganym indeksem Sortcolumn). Sortowanie może być czasochłonne w przypadku większej ilości danych (gdy porównywanie elementów zajmuje dużo czasu).

SortType jest kluczową właściwością w celu wykonania dowolnego sortowania w TListView.

stNone - (wartość domyślna) informująca, że dla danej kontrolki sortowanie nie powinno być wykonywane.
stText - tekst komórek powinien być używany do porównania elementów. Istniejący tekst jest kontrolowany przez właściwość SortColumn. Zauważ, że domyślne porównanie sortowania w rzeczywistości traktuje tekst jako Ansi, a nie UTF8. W związku z tym wynik może być niepożądany w przypadku tekstów nieanglojęzycznych
stData - porównanie właściwości Data domyślne traktowane są jako wartości całkowite (przez rzutowanie wskaźnika na liczbę całkowitą) i sortowane według wartości. (w większości przypadków takie sortowanie jest bezużyteczne, chyba że „Dane” to rzeczywista liczba całkowita rzutowana na wskaźnik)
stBoth - domyślnie traktowane jest jak stText podczas sortowania.

Jeśli nie używasz sortowania tekstu, domyślna metoda porównania nie jest najlepszym podejściem, zamiast tego można użyć porównania niestandardowego. Porównanie niestandardowe jest przypisywane do zdarzenia OnCompare TListView, do którego przekazywane są następujące parametry:

Sender - TListview that's being sorted
Item1 - one TListItem being compared
Item2 - another TListItem being compared to the one
Data - is not used and is always passed as zero. (provided for Delphi compatibility)
Compare - the result of the comparison, that must be populated by the event. The following values should be assigned to the Compare argument.
-1 - if Item1 should show up "earlier" in Ascending order, than Item2. (Item1 is less than Item2)
0 - if two items are equal
1 - if Item2 should show up "earlier" in Ascending order, than Item1. (Item2 is less than Item1)
It's a normal practice to reverse the comparison result value, if SortDirection is descending. I.e.:
procedure TForm1.ListView1OnCompare(Sender: TObject; Item1, Item2: TListItem;
  Data: Integer; var Compare: Integer)
begin
  ... do the comparison...

  if TListView(Sender).SortDirection = sdDescending then
    Compare := -Compare;
end;

The OnCompare event should check for SortType, SortColumn and SortDirection properties of TListView, and do adjust the comparison result respectively of those properties.


Method Sort performs of items, if SortType is other than stNone and SortColumn is assigned to a valid column index.

Method CustomSort performs a one-time sorting using a provided sorting function.

ASortProc: TLVCompare - sorting function
AOptionalParam: PtrInt - sorting parameter

Sorting parameter is ignored (provided for the Delphi compatibility). If ASortProc is passed as nil, then the either sorting OnCompare is used or default sorting.

Typically the sorting can be requested by a user. Whenever a user clicks on a column header, that requires to either sort (initially ascendancy) or to switch to the opposite sorting order (either from ascendant to descendant, or back). It's not a rule, but a common expectation. For some data sets selecting sorting might not make any sense. AutoSort (default value is true)the property of TListview controls, if the listview should be sorted automatically, as soon as user clicks on a column header. AutoSort will have no effect, while SortType is set to stNone.

AlphaSort is a convenience method, that changes the settings to ascending sort (SortDirection=sdAscending) based on the text (SortType=stText) of the first column (SortColumn=0). Note that the actual properties are changed.

Sort Indicator

Originating from: https://bugs.freepascal.org/view.php?id=36281

In trunk since r62567

1) Add a new property SortIndicator to TListViewColumn. The property controls system native sort indicator.

The indicator is acting solely as a decorative feature. (Doesn't have any effect on the sorting). The indicator has 3 possible values

siNone - no sort indicator should be shown
siAscending - ascending indicator should be shown
siDescending - descending indicator should be shown

The property can work independently of other TListview sorting properties.

autosort0.gif

2) Add new property AutoSortIndicator to TListView. The property is intended to be used as a compliment to AutoSort property. If both are enabled, LCL code controls the current selection of the column sortindicator according to AutoSort rules.

autosort2.gif

Early 2021 it was noticed that if you are using Qt5 and you have TListView.SortDirection set to sdAscending (the default), then setting a column's Sort Indicator to siDescending displays an ascending indicator. This does not happen with GTK2 or GTK3. Setting SortDirection to sdDescending makes all other combinations work fine so, seems an easy solution. Logged https://bugs.freepascal.org/view.php?id=38393

Widgetset Implementation

ListView is implemented via TWSCustomListViewClassinterface.

Method Description
SelectAll The method provides a parameter AIsSet.

If the parameter is set to true then all items should selected in the view. If it's false then, all parameters should deselected.

It's important that the event shouldn't trigger any events, as LCL will call SelectChange event by itself.

See also


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu