3 #include "TableColumnList.h" 12 #include "TableColumn.h" 20 TableColumnList::TableColumnList() {
28 TableColumnList::TableColumnList(TableColumnList
const &other) {
36 TableColumnList::~TableColumnList() {
40 delete m_sortingOrder;
41 m_sortingOrder = NULL;
45 TableColumn *&TableColumnList::operator[](
int index) {
46 checkIndexRange(index);
48 return (*m_cols)[index];
52 TableColumn *&TableColumnList::operator[](QString title) {
53 for (
int i = 0; i < m_cols->size(); i++)
54 if (m_cols->at(i)->getTitle() == title)
57 QString msg =
"There is no column with a title of [";
59 msg +=
"] inside this column list";
64 void TableColumnList::append(TableColumn *newCol) {
66 QString msg =
"Attempted to add NULL column to the columnlist";
70 m_cols->append(newCol);
71 m_sortingOrder->append(newCol);
72 connect(newCol, SIGNAL(sortOutDated()),
this, SIGNAL(sortOutDated()));
76 void TableColumnList::prepend(TableColumn *newCol) {
77 m_cols->prepend(newCol);
78 m_sortingOrder->append(newCol);
82 int TableColumnList::indexOf(TableColumn
const *someCol)
const {
84 for (
int i = 0; index < 0 && i < m_cols->size(); i++)
85 if ((*m_cols)[i] == someCol)
92 bool TableColumnList::contains(TableColumn
const *someCol)
const {
93 return indexOf(someCol) != -1;
97 bool TableColumnList::contains(QString columnTitle)
const {
98 bool foundTitle =
false;
99 for (
int i = 0; i < m_cols->size() && !foundTitle; i++)
100 foundTitle = (m_cols->at(i)->getTitle() == columnTitle);
105 void TableColumnList::lower(TableColumn *col,
bool emitSortOutDated) {
106 int oldIndex = m_sortingOrder->indexOf(col);
107 checkIndexRange(oldIndex);
110 if (oldIndex < m_sortingOrder->size() - 1) {
111 m_sortingOrder->removeAt(oldIndex);
112 m_sortingOrder->insert(oldIndex + 1, col);
115 if (emitSortOutDated)
125 void TableColumnList::raise(TableColumn *col,
bool emitSortOutDated) {
126 int oldIndex = m_sortingOrder->indexOf(col);
127 checkIndexRange(oldIndex);
131 m_sortingOrder->removeAt(oldIndex);
132 m_sortingOrder->insert(oldIndex - 1, col);
135 if (emitSortOutDated)
145 void TableColumnList::raiseToTop(TableColumn *col) {
146 while (m_sortingOrder->at(0) != col)
158 int TableColumnList::size()
const {
160 return m_cols->size();
164 TableColumnList &TableColumnList::operator=(
165 TableColumnList other) {
166 swap(*m_cols, *other.m_cols);
167 swap(*m_sortingOrder, *other.m_sortingOrder);
182 if (visibleColumn < visibleCols.size() && visibleColumn >= 0) {
185 for (
int i = 0; i < visibleColumn; i++)
186 indent += visibleCols[i]->getWidth() - 1;
189 maxX = minX + visibleCols[visibleColumn]->getWidth() - 1;
202 for (
int i = 0; i < size(); i++)
203 if (m_cols->at(i)->isVisible())
204 visibleColumns.append(m_cols->at(i));
209 *visibleColumns.m_sortingOrder = *m_sortingOrder;
210 for (
int i = m_sortingOrder->size() - 1; i >= 0; i--)
211 if (!visibleColumns.contains((*visibleColumns.m_sortingOrder)[i]))
212 visibleColumns.m_sortingOrder->removeAt(i);
216 return visibleColumns;
220 int TableColumnList::getVisibleWidth()
const {
223 for (
int i = 0; i < size(); i++)
224 if (m_cols->at(i)->isVisible())
225 width += m_cols->at(i)->getWidth() - 1;
234 ASSERT(m_sortingOrder);
237 for (
int i = 0; i < m_sortingOrder->size(); i++)
238 if (m_sortingOrder->at(i)->getTitle().size())
239 validSortingOrder.append(m_sortingOrder->at(i));
241 return validSortingOrder;
245 QStringList TableColumnList::getSortingOrderAsStrings()
const {
247 for (
int i = 0; i < m_sortingOrder->size(); i++)
248 if (m_sortingOrder->at(i)->getTitle().size())
249 m_sortingOrderStrings.append(m_sortingOrder->at(i)->getTitle());
251 return m_sortingOrderStrings;
255 void TableColumnList::setSortingOrder(
QStringList newOrder) {
256 for (
int i = newOrder.size() - 1; i >= 0; i--)
257 if (contains(newOrder[i]))
258 raiseToTop(
operator[](newOrder[i]));
262 void TableColumnList::checkIndexRange(
int index) {
265 if (index < 0 || index >= m_cols->size()) {
266 QString msg =
"index [";
268 msg +=
"] is out of range. Size of list is: ";
269 msg += m_cols->size();
275 void TableColumnList::nullify() {
277 m_sortingOrder = NULL;
QPair< int, int > getVisibleXRange(int visibleColumn)
This error is for when a programmer made an API call that was illegal.
#define _FILEINFO_
Macro for the filename and line number.
Namespace for ISIS/Bullet specific routines.