Skip to content

Commit 10e9e02

Browse files
committed
add autofilter
1 parent 3a9372c commit 10e9e02

12 files changed

+105
-16
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ This text Russian language.
6767

6868
11.03.2019
6969
- исправлено отображение foreign table
70-
70+
10.09.2019
71+
Окно Server Status
72+
* иправлено падение окна Server Status при аварийном завершении СУБД
73+
- добавлена расцветка процессов которые блокируют другие процессы
74+
Окно Query
75+
- добавлен фильтр в окно результатов запроса. Активируется двойным щелчком мыши по ячейке, текст которой и будет являтся условием фильтра. Снимается из контекстного меню.
76+
При нажатом Alt условие отбора инвертируется (Скрыть строки содержащие значение).
77+
- Для избегания ожиданий при получении информации об объектах. Выставляется клиентский параметр SET lock_timeout=15000 для служебного соединения.
78+
79+
7180

7281

Release_(3.0)/pgAdmin3.exe

15.5 KB
Binary file not shown.

ctl/ctlSQLGrid.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ BEGIN_EVENT_TABLE(ctlSQLGrid, wxGrid)
3030
EVT_GRID_COL_SIZE(ctlSQLGrid::OnGridColSize)
3131
EVT_GRID_LABEL_LEFT_CLICK(ctlSQLGrid::OnLabelClick)
3232
EVT_GRID_CELL_RIGHT_CLICK( ctlSQLGrid::OnCellRightClick)
33+
EVT_PAINT( ctlSQLGrid::OnPaint )
3334
END_EVENT_TABLE()
3435

3536
IMPLEMENT_DYNAMIC_CLASS(ctlSQLGrid, wxGrid)
@@ -60,7 +61,6 @@ ctlSQLGrid::ctlSQLGrid(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
6061

6162
Connect(wxID_ANY, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEventHandler(ctlSQLGrid::OnLabelDoubleClick));
6263
}
63-
6464
void ctlSQLGrid::OnGridColSize(wxGridSizeEvent &event)
6565
{
6666
// Save key="index:label", value=size
@@ -128,8 +128,8 @@ wxString ctlSQLGrid::GetExportLine(int row, wxArrayInt cols)
128128
{
129129
wxString str;
130130
unsigned int col;
131-
132-
if (GetNumberCols() == 0)
131+
132+
if (GetNumberCols() == 0 || GetRowSize(row)==0)
133133
return str;
134134
wxString colsep=settings->GetCopyColSeparator();
135135
if (generatesql) colsep=wxT(",");
@@ -217,7 +217,7 @@ void ctlSQLGrid::AppendColumnHeader(wxString &str, wxArrayInt columns)
217217

218218
int ctlSQLGrid::Copy(bool gensql)
219219
{
220-
wxString str;
220+
wxString str,tmp;
221221
int copied = 0;
222222
size_t i;
223223
generatesql=gensql;
@@ -231,7 +231,9 @@ int ctlSQLGrid::Copy(bool gensql)
231231

232232
for (i = 0 ; i < rows.GetCount() ; i++)
233233
{
234-
str.Append(GetExportLine(rows.Item(i)));
234+
tmp=GetExportLine(rows.Item(i));
235+
if (tmp.IsEmpty()) continue;
236+
str.Append(tmp);
235237
if (rows.GetCount() > 1)
236238
str.Append(END_OF_LINE);
237239
}

ctl/ctlSQLResult.cpp

+44-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ctlSQLResult::ctlSQLResult(wxWindow *parent, pgConn *_conn, wxWindowID id, const
3333

3434
EnableEditing(false);
3535
SetSizer(new wxBoxSizer(wxVERTICAL));
36-
36+
cg=GetGridLineColour();
3737
Connect(wxID_ANY, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEventHandler(ctlSQLResult::OnGridSelect));
3838
}
3939

@@ -358,7 +358,7 @@ wxString ctlSQLResult::SummaryColumn()
358358
for (size_t col = 0 ; col < cols.Count() ; col++)
359359
{
360360
wxString text = GetCellValue(i, cols[col]);
361-
sum=sum+wxAtof(text);
361+
if (GetRowSize(i)>0) sum=sum+wxAtof(text);
362362
}
363363

364364
}
@@ -381,7 +381,7 @@ wxString ctlSQLResult::SummaryColumn()
381381
{
382382
// str.Append(GetExportLine(i, x1, x2));
383383
wxString text = GetCellValue(i, x1);
384-
sum=sum+wxAtof(text);
384+
if (GetRowSize(i)>0) sum=sum+wxAtof(text);
385385

386386
//copied = y2 - y1 + 1;
387387
}
@@ -409,6 +409,47 @@ void ctlSQLResult::OnGridSelect(wxGridRangeSelectEvent &event)
409409
{
410410
SetFocus();
411411
}
412+
void ctlSQLResult::ClearFilter()
413+
{
414+
size_t numRows = GetNumberRows();
415+
int sizerow=GetDefaultRowSize();
416+
for (int i = 0 ; i < numRows; i++)
417+
{
418+
if (GetRowSize(i)>0) continue;
419+
//SetRowSize(i,sizerow);
420+
ShowRow(i);
421+
422+
}
423+
SetGridLineColour(cg);
424+
}
425+
wxString ctlSQLResult::SetFilter(int row,int col,bool reverse)
426+
{
427+
wxString fltval=GetCellValue(row,col);
428+
wxString text;
429+
430+
bool eq;
431+
size_t numRows = GetNumberRows();
432+
int all=0,show=0,hide=0;
433+
for (int i = 0 ; i < numRows; i++)
434+
{
435+
//str.Append(GetExportLine(i, cols));
436+
//SetRowSize(i,sizerow);
437+
if (GetRowSize(i)==0) continue;
438+
eq=(fltval==GetCellValue(i, col));
439+
if (reverse) eq=!eq;
440+
if (!eq) {
441+
HideRow(i);
442+
hide++;
443+
} else show++;
444+
all++;
445+
446+
}
447+
SetGridLineColour(wxColor(0,0,255));
448+
wxString result;
449+
result.Printf(wxT("Show rows:%d hide:%d all:%d"), show,hide,all);
450+
return result;
451+
452+
}
412453

413454
wxString sqlResultTable::GetValue(int row, int col)
414455
{

db/pgConn.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ bool pgConn::Initialize()
262262
PQsetNoticeProcessor(conn, pgNoticeProcessor, this);
263263

264264
wxString sql = wxT("SET DateStyle=ISO;\nSET client_min_messages=notice;\n");
265+
if (!save_applicationname.Contains("query")) sql += wxT("SET lock_timeout=15000;\n");
265266
//if (BackendMinimumVersion(9, 0)) sql += wxT("SET bytea_output=escape;\n");
266267

267268
sql += wxT("SELECT oid, pg_encoding_to_char(encoding) AS encoding, datlastsysoid\n")

frm/frmExport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ bool frmExport::ExportXls(ctlSQLResult *grid)
320320
wxString xmltext=wxEmptyString;
321321
for (row = 0 ; row < rowCount ; row++)
322322
{
323-
323+
if (grid->GetRowSize(row)==0) continue;
324324
line = wxT("<Row>\n");
325325
for (col = 0 ; col < colCount ; col++)
326326
{

frm/frmQuery.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ BEGIN_EVENT_TABLE(frmQuery, pgFrame)
120120
EVT_MENU(MNU_CLEAR, frmQuery::OnClear)
121121
EVT_MENU(MNU_SUMMARY_COL, frmQuery::OnSummary_Column)
122122
EVT_MENU(MNU_COPY_INSERT, frmQuery::OnCopy_Insert)
123+
EVT_MENU(MNU_CLEAR_FILTER, frmQuery::OnClear_Filter)
123124
EVT_MENU(MNU_FIND, frmQuery::OnSearchReplace)
124125
EVT_MENU(MNU_UNDO, frmQuery::OnUndo)
125126
EVT_MENU(MNU_REDO, frmQuery::OnRedo)
@@ -173,6 +174,7 @@ BEGIN_EVENT_TABLE(frmQuery, pgFrame)
173174
EVT_STC_MODIFIED(CTL_SQLQUERY, frmQuery::OnChangeStc)
174175
EVT_STC_UPDATEUI(CTL_SQLQUERY, frmQuery::OnPositionStc)
175176
EVT_GRID_LABEL_RIGHT_CLICK( frmQuery::OnLabelRightClick)
177+
EVT_GRID_CELL_LEFT_DCLICK( frmQuery::OnCellLeftDClick)
176178
EVT_AUI_PANE_CLOSE( frmQuery::OnAuiUpdate)
177179
EVT_TIMER(CTL_TIMERSIZES, frmQuery::OnAdjustSizesTimer)
178180
EVT_TIMER(CTL_TIMERFRM, frmQuery::OnTimer)
@@ -1936,6 +1938,7 @@ void frmQuery::OnLabelRightClick(wxGridEvent &event)
19361938
xmenu->Append(MNU_DELETE, _("&Delete"), _("Delete selected rows."));
19371939
xmenu->Append(MNU_SUMMARY_COL, _("Summary"), _("Summary selected cells."));
19381940
xmenu->Append(MNU_COPY_INSERT, _("Copy Insert format"), _("Copy Insert format."));
1941+
xmenu->Append(MNU_CLEAR_FILTER, _("Clear filter"), _("Clear filter"));
19391942

19401943
if ((rows.GetCount()))
19411944
{
@@ -1949,6 +1952,7 @@ void frmQuery::OnLabelRightClick(wxGridEvent &event)
19491952
xmenu->Enable(MNU_DELETE, false);
19501953
xmenu->Enable(MNU_PASTE, false);
19511954
}
1955+
xmenu->Enable(MNU_CLEAR_FILTER, isfilterresult);
19521956
sqlResult->PopupMenu(xmenu);
19531957
}
19541958
void frmQuery::OnCopy_Insert(wxCommandEvent &ev)
@@ -1960,6 +1964,28 @@ void frmQuery::OnCopy_Insert(wxCommandEvent &ev)
19601964
SetStatusText(s, STATUSPOS_POS);
19611965
}
19621966
}
1967+
void frmQuery::OnCellLeftDClick(wxGridEvent &event)
1968+
{
1969+
int row=event.GetRow();
1970+
int col=event.GetCol();
1971+
bool reverse=event.AltDown();
1972+
wxString s=wxEmptyString;
1973+
s.Printf("wait ...",row,col);
1974+
SetStatusText(s, STATUSPOS_MSGS);
1975+
s=sqlResult->SetFilter(row,col,reverse);
1976+
isfilterresult=true;
1977+
SetStatusText(s, STATUSPOS_MSGS);
1978+
}
1979+
void frmQuery::OnClear_Filter(wxCommandEvent &ev)
1980+
{
1981+
// if (currentControl() == sqlResult)
1982+
{
1983+
wxString s=wxT("Clear filter");
1984+
sqlResult->ClearFilter();
1985+
SetStatusText(s, STATUSPOS_MSGS);
1986+
isfilterresult=false;
1987+
}
1988+
}
19631989

19641990
void frmQuery::OnSummary_Column(wxCommandEvent &ev)
19651991
{
@@ -2803,7 +2829,7 @@ void frmQuery::execQuery(const wxString &query, int resultToRetrieve, bool singl
28032829
setExtendedTitle();
28042830

28052831
aborted = false;
2806-
2832+
isfilterresult=false;
28072833
QueryExecInfo *qi = new QueryExecInfo();
28082834
qi->queryOffset = queryOffset;
28092835
qi->toFileExportForm = NULL;

frm/frmStatus.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -1923,9 +1923,15 @@ void frmStatus::OnRefreshLocksTimer(wxTimerEvent &event)
19231923
lockList->SetItem(row, colpos++, dataSet2->GetVal(wxT("mode")));
19241924

19251925
if (dataSet2->GetVal(wxT("granted")) == wxT("t"))
1926+
{
19261927
lockList->SetItem(row, colpos++, _("Yes"));
1927-
else
1928-
lockList->SetItem(row, colpos++, _("No"));
1928+
lockList->SetItemBackgroundColour(row,lockList->GetBackgroundColour());
1929+
}
1930+
else {
1931+
lockList->SetItem(row, colpos++, _("No"));
1932+
lockList->SetItemBackgroundColour(row, wxColour(settings->GetBlockedProcessColour()));
1933+
1934+
}
19291935

19301936
wxString qry = dataSet2->GetVal(wxT("query"));
19311937

include/ctl/ctlSQLGrid.h

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class ctlSQLGrid : public wxGrid
6060
wxString GetColKeyValue(int col);
6161
void AppendColumnHeader(wxString &str, int start, int end);
6262
void AppendColumnHeader(wxString &str, wxArrayInt columns);
63-
6463
// Stores sizes of colums explicitly resized by user
6564
ColKeySizeHashMap colSizes;
6665
// Max size for each column

include/ctl/ctlSQLResult.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ctlSQLResult : public ctlSQLGrid
3434
long NumRows() const;
3535
long InsertedCount() const;
3636
OID InsertedOid() const;
37-
37+
wxColor cg;
3838
int Abort();
3939

4040
bool Export();
@@ -47,6 +47,7 @@ class ctlSQLResult : public ctlSQLGrid
4747

4848
wxString OnGetItemText(long item, long col) const;
4949
wxString SummaryColumn();
50+
void ClearFilter();
5051
bool IsColText(int col);
5152
bool hasRowNumber()
5253
{
@@ -68,6 +69,7 @@ class ctlSQLResult : public ctlSQLGrid
6869
void SetMaxRows(int rows);
6970
void ResultsFinished();
7071
void OnGridSelect(wxGridRangeSelectEvent &event);
72+
wxString SetFilter(int row,int col,bool reverse);
7173

7274
wxArrayString colNames;
7375
wxArrayString colTypes;

include/frm/frmQuery.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class frmQuery : public pgFrame
180180
void OnChangeStc(wxStyledTextEvent &event);
181181
void OnPositionStc(wxStyledTextEvent &event);
182182
void OnLabelRightClick(wxGridEvent &event);
183+
void OnCellLeftDClick(wxGridEvent &event);
183184
void OnClose(wxCloseEvent &event);
184185
void OnSetFocus(wxFocusEvent &event);
185186
void OnContents(wxCommandEvent &event);
@@ -206,6 +207,7 @@ class frmQuery : public pgFrame
206207
void OnClear(wxCommandEvent &event);
207208
void OnSummary_Column(wxCommandEvent &event);
208209
void OnCopy_Insert(wxCommandEvent &event);
210+
void OnClear_Filter(wxCommandEvent &event);
209211
void OnSearchReplace(wxCommandEvent &event);
210212
void OnUndo(wxCommandEvent &event);
211213
void OnRedo(wxCommandEvent &event);
@@ -315,7 +317,7 @@ class frmQuery : public pgFrame
315317
queryFavouriteFolder *favourites;
316318
queryMacroList *macros;
317319
queryMacroList *autoreplace;
318-
320+
bool isfilterresult;
319321
bool aborted;
320322
bool lastFileFormat;
321323
bool m_loadingfile;

include/frm/menu.h

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ enum
7676
MNU_AUTOSELECTQUERY,
7777
MNU_SUMMARY_COL,
7878
MNU_COPY_INSERT,
79+
MNU_CLEAR_FILTER,
7980
MNU_AUTOROLLBACK,
8081
MNU_AUTOCOMMIT,
8182
MNU_CLEARHISTORY,

0 commit comments

Comments
 (0)