9#include "TableColumnList.h"
17#include "IException.h"
18#include "TableColumn.h"
26 TableColumnList::TableColumnList() {
29 m_cols =
new QList< TableColumn * >;
30 m_sortingOrder =
new QList< TableColumn * >;
34 TableColumnList::TableColumnList(TableColumnList
const &other) {
37 m_cols =
new QList< TableColumn * >(*other.m_cols);
38 m_sortingOrder =
new QList< TableColumn * >(*other.m_sortingOrder);
42 TableColumnList::~TableColumnList() {
46 delete m_sortingOrder;
47 m_sortingOrder = NULL;
51 TableColumn *&TableColumnList::operator[](
int index) {
52 checkIndexRange(index);
54 return (*m_cols)[index];
58 TableColumn *&TableColumnList::operator[](QString title) {
59 for (
int i = 0; i < m_cols->size(); i++)
60 if (m_cols->at(i)->getTitle() == title)
63 QString msg =
"There is no column with a title of [";
65 msg +=
"] inside this column list";
70 void TableColumnList::append(TableColumn *newCol) {
72 QString msg =
"Attempted to add NULL column to the columnlist";
76 m_cols->append(newCol);
77 m_sortingOrder->append(newCol);
78 connect(newCol, SIGNAL(sortOutDated()),
this, SIGNAL(sortOutDated()));
82 void TableColumnList::prepend(TableColumn *newCol) {
83 m_cols->prepend(newCol);
84 m_sortingOrder->append(newCol);
88 int TableColumnList::indexOf(TableColumn
const *someCol)
const {
90 for (
int i = 0; index < 0 && i < m_cols->size(); i++)
91 if ((*m_cols)[i] == someCol)
98 bool TableColumnList::contains(TableColumn
const *someCol)
const {
99 return indexOf(someCol) != -1;
103 bool TableColumnList::contains(QString columnTitle)
const {
104 bool foundTitle =
false;
105 for (
int i = 0; i < m_cols->size() && !foundTitle; i++)
106 foundTitle = (m_cols->at(i)->getTitle() == columnTitle);
111 void TableColumnList::lower(TableColumn *col,
bool emitSortOutDated) {
112 int oldIndex = m_sortingOrder->indexOf(col);
113 checkIndexRange(oldIndex);
116 if (oldIndex < m_sortingOrder->size() - 1) {
117 m_sortingOrder->removeAt(oldIndex);
118 m_sortingOrder->insert(oldIndex + 1, col);
121 if (emitSortOutDated)
131 void TableColumnList::raise(TableColumn *col,
bool emitSortOutDated) {
132 int oldIndex = m_sortingOrder->indexOf(col);
133 checkIndexRange(oldIndex);
137 m_sortingOrder->removeAt(oldIndex);
138 m_sortingOrder->insert(oldIndex - 1, col);
141 if (emitSortOutDated)
151 void TableColumnList::raiseToTop(TableColumn *col) {
152 while (m_sortingOrder->at(0) != col)
164 int TableColumnList::size()
const {
165 return m_cols->size();
169 TableColumnList &TableColumnList::operator=(
170 TableColumnList other) {
171 swap(*m_cols, *other.m_cols);
172 swap(*m_sortingOrder, *other.m_sortingOrder);
187 if (visibleColumn < visibleCols.size() && visibleColumn >= 0) {
190 for (
int i = 0; i < visibleColumn; i++)
191 indent += visibleCols[i]->getWidth() - 1;
194 maxX = minX + visibleCols[visibleColumn]->getWidth() - 1;
197 return QPair<int, int>(minX, maxX);
207 for (
int i = 0; i < size(); i++)
208 if (m_cols->at(i)->isVisible())
209 visibleColumns.append(m_cols->at(i));
214 *visibleColumns.m_sortingOrder = *m_sortingOrder;
215 for (
int i = m_sortingOrder->size() - 1; i >= 0; i--)
216 if (!visibleColumns.contains((*visibleColumns.m_sortingOrder)[i]))
217 visibleColumns.m_sortingOrder->removeAt(i);
221 return visibleColumns;
225 int TableColumnList::getVisibleWidth()
const {
228 for (
int i = 0; i < size(); i++)
229 if (m_cols->at(i)->isVisible())
230 width += m_cols->at(i)->getWidth() - 1;
238 QList< TableColumn * > TableColumnList::getSortingOrder() {
240 QList< TableColumn * > validSortingOrder;
241 for (
int i = 0; i < m_sortingOrder->size(); i++)
242 if (m_sortingOrder->at(i)->getTitle().size())
243 validSortingOrder.append(m_sortingOrder->at(i));
245 return validSortingOrder;
249 QStringList TableColumnList::getSortingOrderAsStrings()
const {
251 for (
int i = 0; i < m_sortingOrder->size(); i++)
252 if (m_sortingOrder->at(i)->getTitle().size())
253 m_sortingOrderStrings.append(m_sortingOrder->at(i)->getTitle());
255 return m_sortingOrderStrings;
259 void TableColumnList::setSortingOrder(
QStringList newOrder) {
260 for (
int i = newOrder.size() - 1; i >= 0; i--)
261 if (contains(newOrder[i]))
262 raiseToTop(
operator[](newOrder[i]));
266 void TableColumnList::checkIndexRange(
int index) {
268 if (index < 0 || index >= m_cols->size()) {
269 QString msg =
"index [";
271 msg +=
"] is out of range. Size of list is: ";
272 msg += m_cols->size();
278 void TableColumnList::nullify() {
280 m_sortingOrder = NULL;
@ Programmer
This error is for when a programmer made an API call that was illegal.
QPair< int, int > getVisibleXRange(int visibleColumn)
This is free and unencumbered software released into the public domain.