1
/***************************************************************************
2
qgsattributetable.h - description
4
begin : Sat Nov 23 2002
5
copyright : (C) 2002 by Gary E.Sherman
6
email : sherman at mrcc dot com
7
Romans 3:23=>Romans 6:23=>Romans 5:8=>Romans 10:9,10=>Romans 12
8
***************************************************************************/
10
/***************************************************************************
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
17
***************************************************************************/
18
/* $Id: qgsattributetable.h 5706 2006-08-18 05:32:55Z mhugent $ */
19
#ifndef QGSATTRIBUTETABLE_H
20
#define QGSATTRIBUTETABLE_H
35
#include "qgsattributeaction.h"
40
*@author Gary E.Sherman
43
class QgsAttributeTable:public Q3Table
48
QgsAttributeTable(QWidget * parent = 0, const char *name = 0);
51
/**Inserts the feature with the specified id into rowIdMap. This function has to be called (e.g. from QgsShapeFileLayer) when a row is inserted into the table*/
52
void insertFeatureId(int id, int row);
53
/**Selects the row which belongs to the feature with the specified id*/
54
void selectRowWithId(int id);
55
/**Sorts a column. This method replaces the one from QTable to allow numeric sorting*/
56
virtual void sortColumn(int col, bool ascending=true, bool wholeRows=false);
57
/* Use this to give this class the current attribute actions,
58
which are used when the user requests a popup menu */
59
void setAttributeActions(const QgsAttributeAction& actions)
60
{ mActions = actions; }
61
/**Returns if the table contains uncommited changes*/
62
bool edited() const {return mEdited;}
63
/**Switches editing mode on and off*/
64
void setEditable(bool enabled){mEditable=enabled;}
65
/**Adds an attribute to the table (but does not commit it yet)
66
@param name attribute name
67
@param type attribute type
68
@return false in case of a name conflict, true in case of success*/
69
bool addAttribute(const QString& name, const QString& type);
70
/**Deletes an attribute (but does not commit it)
71
@param name attribute name*/
72
void deleteAttribute(const QString& name);
74
/** Copies the selected rows to the clipboard
75
Deprecated: See QgisApp::editCopy() instead */
76
void copySelectedRows();
79
Attempts to commit any changes to disk. Returns the result of the attempt.
80
If a commit fails, the in-memory changes are left alone.
82
This allows editing to continue if the commit failed on e.g. a
83
disallowed value in a Postgres database - the user can re-edit and try
86
Delegates to QgsVectorLayer to decide, which changes
87
belong to not commited features or to commited ones.
90
bool commitChanges(QgsVectorLayer* layer);
92
/**Discard all changes and restore
93
the state before editing was started*/
94
bool rollBack(QgsVectorLayer* layer);
95
/**Fills the contents of a provider into this table*/
96
void fillTable(QgsVectorLayer* layer);
97
/**Swaps the selected rows such that the selected ones are on the top of the table*/
98
void bringSelectedToTop();
99
/** Selects rows with chosen feature IDs */
100
void selectRowsWithId(const std::vector<int>& ids);
101
/** Shows only rows with chosen feature IDs, others get hidden */
102
void showRowsWithId(const std::vector<int>& ids);
103
/** Shows all rows */
107
void columnClicked(int col);
108
void rowClicked(int row);
109
// Called when the user requests a popup menu
110
void popupMenu(int row, int col, const QPoint& pos);
111
// Called when the user chooses an item on the popup menu
112
void popupItemSelected(QAction * menuAction);
114
void handleChangedSelections();
115
/**Writes changed values to 'mChangedValues'*/
116
void storeChangedValue(int row, int column);
119
/**Flag telling if the ctrl-button or the shift-button is pressed*/
121
/**Search tree to find a row corresponding to a feature id*/
122
QMap<int,int> rowIdMap;
123
/**Flag indicating, which sorting order should be used*/
126
/**True if table has been edited and contains uncommited changes*/
128
/**Map containing the added attributes. The key is the attribute name
129
and the value the attribute type*/
130
std::map<QString,QString> mAddedAttributes;
131
/**Set containing the attribute names of deleted attributes*/
132
std::set<QString> mDeletedAttributes;
133
/**Nested map containing the changed attribute values. The int is the feature id,
134
the first QString the attribute name and the second QString the new value*/
135
std::map<int,std::map<QString,QString> > mChangedValues;
136
/**Stors the numbers of the last selected rows. This is used to check for selection changes before emit repaintRequested()*/
137
std::set<int> mLastSelectedRows;
139
/**Compares the content of two cells either alphanumeric or numeric. If 'ascending' is true, -1 means s1 is less, 0 equal, 1 greater. If 'ascending' is false, -1 means s1 is more, 0 equal, 1 greater. This method is used mainly to sort a column*/
140
int compareItems(QString s1, QString s2, bool ascending, bool alphanumeric);
141
void keyPressEvent(QKeyEvent* ev);
142
void keyReleaseEvent(QKeyEvent* ev);
143
/**Method used by sortColumn (implementation of a quicksort)*/
144
void qsort(int lower, int upper, int col, bool ascending, bool alphanumeric);
145
/**Clears mAddedAttributes, mDeletedAttributes and mChangedValues*/
146
void clearEditingStructures();
147
/**Removes the column belonging to an attribute from the table
148
@name attribut name*/
149
void removeAttrColumn(const QString& name);
150
/** puts attributes of feature to the chosen table row */
151
void putFeatureInTable(int row, QgsFeature* fet);
152
void contentsMouseReleaseEvent(QMouseEvent* e);
153
/**This function compares the current selection and the selection of the last repaint. Returns true if there are differences in the selection.
154
Also, mLastSelectedRows is updated*/
155
bool checkSelectionChanges();
158
/**Is emitted when a row was selected*/
160
/**Is emitted when all rows have been deselected*/
161
void selectionRemoved();
162
/**Is emmited when a set of related selection and deselection signals have been emitted*/
163
void repaintRequested();
166
// Data to do with providing a popup menu of actions that
167
std::vector<std::pair<QString, QString> > mActionValues;
170
QgsAttributeAction mActions;