Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "qxtscheduleviewheadermodel_p.h"
00027 #include "qxtscheduleview.h"
00028 #include "qxtscheduleview_p.h"
00029 #include <QDateTime>
00030 #include <QDebug>
00031
00032 QxtScheduleViewHeaderModel::QxtScheduleViewHeaderModel(QObject *parent) : QAbstractTableModel(parent)
00033 , m_rowCountBuffer(0)
00034 , m_colCountBuffer(0)
00035 {
00036
00037 }
00038
00039 void QxtScheduleViewHeaderModel::newZoomDepth(const int zoomDepth)
00040 {
00041 Q_UNUSED(zoomDepth);
00042
00043 if (this->m_dataSource)
00044 {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 m_rowCountBuffer = m_dataSource->rows();
00056 reset();
00057
00058 }
00059 }
00060
00061 void QxtScheduleViewHeaderModel::viewModeChanged(const int viewMode)
00062 {
00063 Q_UNUSED(viewMode);
00064
00065 if (this->m_dataSource)
00066 {
00067 beginRemoveRows(QModelIndex(), 0, m_rowCountBuffer);
00068 m_rowCountBuffer = 0;
00069 endRemoveRows();
00070
00071 beginInsertRows(QModelIndex(), 0, m_dataSource->rows());
00072 m_rowCountBuffer = m_dataSource->rows();
00073 endInsertRows();
00074
00075 beginRemoveColumns(QModelIndex(), 0, m_colCountBuffer);
00076 m_colCountBuffer = 0;
00077 endRemoveColumns();
00078
00079 beginInsertColumns(QModelIndex(), 0, m_dataSource->cols());
00080 m_colCountBuffer = m_dataSource->cols();
00081 endInsertColumns();
00082 }
00083 }
00084
00085 void QxtScheduleViewHeaderModel::setDataSource(QxtScheduleView *dataSource)
00086 {
00087 if (this->m_dataSource)
00088 {
00089 disconnect(m_dataSource, SIGNAL(newZoomDepth(const int)), this, SLOT(newZoomDepth(const int)));
00090 disconnect(m_dataSource, SIGNAL(viewModeChanged(const int)), this, SLOT(viewModeChanged(const int)));
00091
00092 emit beginRemoveRows(QModelIndex(), 0, m_rowCountBuffer);
00093 m_rowCountBuffer = 0;
00094 emit endRemoveRows();
00095
00096 emit beginRemoveColumns(QModelIndex(), 0, m_colCountBuffer);
00097 m_colCountBuffer = 0;
00098 emit endRemoveColumns();
00099 }
00100
00101 if (dataSource)
00102 {
00103 connect(dataSource, SIGNAL(newZoomDepth(const int)), this, SLOT(newZoomDepth(const int)));
00104 connect(dataSource, SIGNAL(viewModeChanged(const int)), this, SLOT(viewModeChanged(const int)));
00105
00106 emit beginInsertRows(QModelIndex(), 0, dataSource->rows());
00107 m_rowCountBuffer = dataSource->rows();
00108 emit endInsertRows();
00109
00110 emit beginInsertColumns(QModelIndex(), 0, dataSource->cols());
00111 m_colCountBuffer = dataSource->cols();
00112 emit endInsertColumns();
00113 }
00114
00115 m_dataSource = dataSource;
00116 }
00117
00118 QModelIndex QxtScheduleViewHeaderModel::parent(const QModelIndex & index) const
00119 {
00120 Q_UNUSED(index);
00121 return QModelIndex();
00122 }
00123
00124 int QxtScheduleViewHeaderModel::rowCount(const QModelIndex & parent) const
00125 {
00126 if (!parent.isValid())
00127 {
00128 if (this->m_dataSource)
00129 return m_dataSource->rows();
00130 }
00131 return 0;
00132 }
00133
00134 int QxtScheduleViewHeaderModel::columnCount(const QModelIndex & parent) const
00135 {
00136 if (!parent.isValid())
00137 {
00138 if (this->m_dataSource)
00139 return m_dataSource->cols();
00140 }
00141 return 0;
00142 }
00143
00144 QVariant QxtScheduleViewHeaderModel::data(const QModelIndex & index, int role) const
00145 {
00146 Q_UNUSED(index);
00147 Q_UNUSED(role);
00148 return QVariant();
00149 }
00150
00151 bool QxtScheduleViewHeaderModel::setData(const QModelIndex & index, const QVariant & value, int role)
00152 {
00153 Q_UNUSED(index);
00154 Q_UNUSED(value);
00155 Q_UNUSED(role);
00156 return false;
00157 }
00158
00159 bool QxtScheduleViewHeaderModel::insertRow(int row, const QModelIndex & parent)
00160 {
00161 Q_UNUSED(row);
00162 Q_UNUSED(parent);
00163 return false;
00164 }
00165
00166 QVariant QxtScheduleViewHeaderModel::headerData(int section, Qt::Orientation orientation, int role) const
00167 {
00168 if (!m_dataSource)
00169 return QVariant();
00170 #if 0
00171 if (role == Qt::SizeHintRole)
00172 {
00173 if (this->viewModel)
00174 {
00175 return viewModel->headerData(section, orientation, role);
00176 }
00177 }
00178 #endif
00179
00180 if (role == Qt::DisplayRole || role == Qt::EditRole)
00181 {
00182 if (Qt::Horizontal == orientation)
00183 {
00184 int iTableOffset = m_dataSource->qxt_d().visualIndexToOffset(0, section);
00185 QDateTime startTime = QDateTime::fromTime_t(m_dataSource->qxt_d().offsetToUnixTime(iTableOffset));
00186 return QVariant(startTime.date().toString());
00187 }
00188 else
00189 {
00190 int iTableOffset = m_dataSource->qxt_d().visualIndexToOffset(section, 0);
00191 QTime time = QDateTime::fromTime_t(m_dataSource->qxt_d().offsetToUnixTime(iTableOffset)).time();
00192 return QVariant(time.toString());
00193 }
00194 }
00195
00196 return QVariant();
00197 }
00198
00199 Qt::ItemFlags QxtScheduleViewHeaderModel::flags(const QModelIndex & index) const
00200 {
00201 Q_UNUSED(index);
00202 return Qt::ItemIsEnabled;
00203 }
00204
00205 bool QxtScheduleViewHeaderModel::hasChildren(const QModelIndex & parent) const
00206 {
00207 Q_UNUSED(parent);
00208 return false;
00209 }
00210
00211