Qt 4.8
Public Functions | Public Variables | List of all members
QCalendarModel Class Reference
Inheritance diagram for QCalendarModel:
QAbstractTableModel QAbstractItemModel QObject

Public Functions

void cellForDate (const QDate &date, int *row, int *column) const
 
int columnCount (const QModelIndex &) const
 Returns the number of columns for the children of the given parent. More...
 
int columnForDayOfWeek (Qt::DayOfWeek day) const
 
int columnForFirstOfMonth (const QDate &date) const
 
QVariant data (const QModelIndex &index, int role) const
 Returns the data stored under the given role for the item referred to by the index. More...
 
QDate dateForCell (int row, int column) const
 
QString dayName (Qt::DayOfWeek day) const
 
Qt::DayOfWeek dayOfWeekForColumn (int section) const
 
Qt::DayOfWeek firstColumnDay () const
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Returns the item flags for the given index. More...
 
QTextCharFormat formatForCell (int row, int col) const
 
bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count new columns into the model before the given column. More...
 
bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count rows into the model before the given row. More...
 
void internalUpdate ()
 
 QCalendarModel (QObject *parent=0)
 
QDate referenceDate () const
 
bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count columns starting with the given column under parent parent from the model. More...
 
bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count rows starting with the given row under parent parent from the model. More...
 
int rowCount (const QModelIndex &) const
 Returns the number of rows under the given parent. More...
 
void setDate (const QDate &d)
 
void setFirstColumnDay (Qt::DayOfWeek dayOfWeek)
 
void setHorizontalHeaderFormat (QCalendarWidget::HorizontalHeaderFormat format)
 
void setMaximumDate (const QDate &date)
 
void setMinimumDate (const QDate &date)
 
void setRange (const QDate &min, const QDate &max)
 
void setView (QCalendarView *view)
 
void setWeekNumbersShown (bool show)
 
void showMonth (int year, int month)
 
bool weekNumbersShown () const
 
- Public Functions inherited from QAbstractTableModel
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Reimplemented Function More...
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns the index of the data in row and column with parent. More...
 
 QAbstractTableModel (QObject *parent=0)
 Constructs an abstract table model for the given parent. More...
 
 ~QAbstractTableModel ()
 Destroys the abstract table model. More...
 
- Public Functions inherited from QAbstractItemModel
virtual QModelIndex buddy (const QModelIndex &index) const
 Returns a model index for the buddy of the item represented by index. More...
 
virtual bool canFetchMore (const QModelIndex &parent) const
 Returns true if there is more data available for parent; otherwise returns false. More...
 
virtual void fetchMore (const QModelIndex &parent)
 Fetches any available data for the items with the parent specified by the parent index. More...
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false. More...
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 Returns the data for the given role and section in the header with the specified orientation. More...
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex())
 Inserts a single column before the given column in the child items of the parent specified. More...
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 Inserts a single row before the given row in the child items of the parent specified. More...
 
virtual QMap< int, QVariantitemData (const QModelIndex &index) const
 Returns a map with values for all predefined roles in the model for the item at the given index. More...
 
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Returns a list of indexes for the items in the column of the start index where data stored under the given role matches the specified value. More...
 
virtual QMimeDatamimeData (const QModelIndexList &indexes) const
 Returns an object that contains serialized items of data corresponding to the list of indexes specified. More...
 
virtual QStringList mimeTypes () const
 Returns a list of MIME types that can be used to describe a list of model indexes. More...
 
 QAbstractItemModel (QObject *parent=0)
 Constructs an abstract item model with the given parent. More...
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex())
 Removes the given column from the child items of the parent specified. More...
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 Removes the given row from the child items of the parent specified. More...
 
const QHash< int, QByteArray > & roleNames () const
 Returns the model's role names. More...
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Sets the role data for the item at index to value. More...
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 Sets the data for the given role and section in the header with the specified orientation to the value supplied. More...
 
virtual bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole. More...
 
void setSupportedDragActions (Qt::DropActions)
 Sets the supported drag actions for the items in the model. More...
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const
 Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. More...
 
virtual void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Sorts the model by column in the given order. More...
 
virtual QSize span (const QModelIndex &index) const
 Returns the row and column span of the item represented by index. More...
 
Qt::DropActions supportedDragActions () const
 Returns the actions supported by the data in this model. More...
 
virtual Qt::DropActions supportedDropActions () const
 Returns the drop actions supported by this model. More...
 
virtual ~QAbstractItemModel ()
 Destroys the abstract item model. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

QDate m_date
 
QMap< QDate, QTextCharFormatm_dateFormats
 
QMap< Qt::DayOfWeek, QTextCharFormatm_dayFormats
 
int m_firstColumn
 
Qt::DayOfWeek m_firstDay
 
int m_firstRow
 
QTextCharFormat m_headerFormat
 
QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat
 
QDate m_maximumDate
 
QDate m_minimumDate
 
int m_shownMonth
 
int m_shownYear
 
QCalendarViewm_view
 
bool m_weekNumbersShown
 

Additional Inherited Members

- Public Slots inherited from QAbstractItemModel
virtual void revert ()
 Lets the model know that it should discard cached information. More...
 
virtual bool submit ()
 Lets the model know that it should submit cached information to permanent storage. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QAbstractItemModel
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are inserted into the model. More...
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 This signal is emitted just before columns are moved within the model. More...
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are removed from the model. More...
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been inserted into the model. More...
 
void columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 This signal is emitted after columns have been moved within the model. More...
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been removed from the model. More...
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 This signal is emitted whenever the data in an existing item changes. More...
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 This signal is emitted whenever a header is changed. More...
 
void layoutAboutToBeChanged ()
 This signal is emitted just before the layout of a model is changed. More...
 
void layoutChanged ()
 This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. More...
 
void modelAboutToBeReset ()
 This signal is emitted when reset() is called, before the model's internal state (e. More...
 
void modelReset ()
 This signal is emitted when reset() is called, after the model's internal state (e. More...
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are inserted into the model. More...
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 This signal is emitted just before rows are moved within the model. More...
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are removed from the model. More...
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been inserted into the model. More...
 
void rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 This signal is emitted after rows have been moved within the model. More...
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been removed from the model. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QAbstractItemModel
void resetInternalData ()
 This slot is called just after the internal data of a model is cleared while it is being reset. More...
 
- Protected Functions inherited from QAbstractTableModel
 QAbstractTableModel (QAbstractItemModelPrivate &dd, QObject *parent)
 Constructs an abstract table model with dd and the given parent. More...
 
- Protected Functions inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 Begins a column insertion operation. More...
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 Begins a row insertion operation. More...
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 Begins a column move operation. More...
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 Begins a row move operation. More...
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 Begins a column removal operation. More...
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 Begins a row removal operation. More...
 
void beginResetModel ()
 Begins a model reset operation. More...
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index. More...
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list. More...
 
QModelIndex createIndex (int row, int column, void *data=0) const
 Creates a model index for the given row and column with the internal pointer ptr. More...
 
QModelIndex createIndex (int row, int column, int id) const
 Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. More...
 
QModelIndex createIndex (int row, int column, quint32 id) const
 Creates a model index for the given row and column with the internal identifier, id. More...
 
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
 
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
 
void endInsertColumns ()
 Ends a column insertion operation. More...
 
void endInsertRows ()
 Ends a row insertion operation. More...
 
void endMoveColumns ()
 Ends a column move operation. More...
 
void endMoveRows ()
 Ends a row move operation. More...
 
void endRemoveColumns ()
 Ends a column removal operation. More...
 
void endRemoveRows ()
 Ends a row removal operation. More...
 
void endResetModel ()
 Completes a model reset operation. More...
 
QModelIndexList persistentIndexList () const
 Returns the list of indexes stored as persistent indexes in the model. More...
 
 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0)
 
void reset ()
 Resets the model to its original state in any attached views. More...
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 Sets the model's role names to roleNames. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 815 of file qcalendarwidget.cpp.

Constructors and Destructors

◆ QCalendarModel()

QCalendarModel::QCalendarModel ( QObject parent = 0)

Definition at line 936 of file qcalendarwidget.cpp.

937  : QAbstractTableModel(parent)
938 {
941  m_maximumDate = QDate(7999, 12, 31);
942  m_shownYear = m_date.year();
946  m_weekNumbersShown = true;
947  m_firstColumn = 1;
948  m_firstRow = 1;
949  m_view = 0;
950 }
QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
QCalendarView * m_view
The QDate class provides date functions.
Definition: qdatetime.h:55
static QDate fromJulianDay(int jd)
Converts the Julian day jd to a QDate.
Definition: qdatetime.h:133
static QDate currentDate()
Returns the current date, as reported by the system clock.
Definition: qdatetime.cpp:3115
Qt::DayOfWeek m_firstDay
QAbstractTableModel(QObject *parent=0)
Constructs an abstract table model for the given parent.
int year() const
Returns the year of this date.
Definition: qdatetime.cpp:353

Functions

◆ cellForDate()

void QCalendarModel::cellForDate ( const QDate date,
int *  row,
int *  column 
) const

Definition at line 1019 of file qcalendarwidget.cpp.

Referenced by QCalendarWidgetPrivate::update(), and QCalendarWidgetPrivate::updateCurrentPage().

1020 {
1021  if (!row && !column)
1022  return;
1023 
1024  if (row)
1025  *row = -1;
1026  if (column)
1027  *column = -1;
1028 
1029  const QDate refDate = referenceDate();
1030  if (!refDate.isValid())
1031  return;
1032 
1033  const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate);
1034  const int requestedPosition = refDate.daysTo(date) - m_firstColumn + columnForFirstOfShownMonth + refDate.day() - 1;
1035 
1036  int c = requestedPosition % 7;
1037  int r = requestedPosition / 7;
1038  if (c < 0) {
1039  c += 7;
1040  r -= 1;
1041  }
1042 
1043  if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
1044  r += 1;
1045 
1046  if (r < 0 || r > RowCount - 1 || c < 0 || c > ColumnCount - 1)
1047  return;
1048 
1049  if (row)
1050  *row = r + m_firstRow;
1051  if (column)
1052  *column = c + m_firstColumn;
1053 }
int daysTo(const QDate &) const
Returns the number of days from this date to d (which is negative if d is earlier than this date)...
Definition: qdatetime.cpp:1111
unsigned char c[8]
Definition: qnumeric_p.h:62
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
The QDate class provides date functions.
Definition: qdatetime.h:55
QDate referenceDate() const
int columnForFirstOfMonth(const QDate &date) const

◆ columnCount()

int QCalendarModel::columnCount ( const QModelIndex parent) const
inlinevirtual

Returns the number of columns for the children of the given parent.

In most subclasses, the number of columns is independent of the parent.

For example:

int DomModel::columnCount(const QModelIndex &/*parent*/) const
{
return 3;
}
Note
When implementing a table based model, columnCount() should return 0 when the parent is valid.
See also
rowCount()

Implements QAbstractItemModel.

Definition at line 823 of file qcalendarwidget.cpp.

◆ columnForDayOfWeek()

int QCalendarModel::columnForDayOfWeek ( Qt::DayOfWeek  day) const

Definition at line 963 of file qcalendarwidget.cpp.

Referenced by columnForFirstOfMonth(), and data().

964 {
965  if (day < 1 || day > 7)
966  return -1;
967  int column = (int)day - (int)m_firstDay;
968  if (column < 0)
969  column += 7;
970  return column + m_firstColumn;
971 }
Qt::DayOfWeek m_firstDay

◆ columnForFirstOfMonth()

int QCalendarModel::columnForFirstOfMonth ( const QDate date) const

Definition at line 997 of file qcalendarwidget.cpp.

Referenced by cellForDate(), and dateForCell().

998 {
999  return (columnForDayOfWeek(static_cast<Qt::DayOfWeek>(date.dayOfWeek())) - (date.day() % 7) + 8) % 7;
1000 }
int dayOfWeek() const
Returns the weekday (1 = Monday to 7 = Sunday) for this date.
Definition: qdatetime.cpp:408
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
int columnForDayOfWeek(Qt::DayOfWeek day) const

◆ data()

QVariant QCalendarModel::data ( const QModelIndex index,
int  role 
) const
virtual

Returns the data stored under the given role for the item referred to by the index.

Note
If you do not have a value to return, return an invalid QVariant instead of returning 0.
See also
Qt::ItemDataRole, setData(), headerData()

Implements QAbstractItemModel.

Definition at line 1113 of file qcalendarwidget.cpp.

1114 {
1115  if (role == Qt::TextAlignmentRole)
1116  return (int) Qt::AlignCenter;
1117 
1118  int row = index.row();
1119  int column = index.column();
1120 
1121  if(role == Qt::DisplayRole) {
1122  if (m_weekNumbersShown && column == HeaderColumn
1123  && row >= m_firstRow && row < m_firstRow + RowCount) {
1125  if (date.isValid())
1126  return date.weekNumber();
1127  }
1129  && column >= m_firstColumn && column < m_firstColumn + ColumnCount)
1130  return dayName(dayOfWeekForColumn(column));
1131  QDate date = dateForCell(row, column);
1132  if (date.isValid())
1133  return date.day();
1134  return QString();
1135  }
1136 
1137  QTextCharFormat fmt = formatForCell(row, column);
1138  if (role == Qt::BackgroundColorRole)
1139  return fmt.background().color();
1140  if (role == Qt::TextColorRole)
1141  return fmt.foreground().color();
1142  if (role == Qt::FontRole)
1143  return fmt.font();
1144  if (role == Qt::ToolTipRole)
1145  return fmt.toolTip();
1146  return QVariant();
1147 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QFont font() const
Returns the font for this character format.
QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
int weekNumber(int *yearNum=0) const
Returns the week number (1 to 53), and stores the year in {yearNumber} unless yearNumber is null (the...
Definition: qdatetime.cpp:487
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
The QDate class provides date functions.
Definition: qdatetime.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDate dateForCell(int row, int column) const
int row() const
Returns the row this model index refers to.
Qt::DayOfWeek dayOfWeekForColumn(int section) const
QString toolTip() const
Returns the tool tip that is displayed for a fragment of text.
Definition: qtextformat.h:496
QBrush background() const
Returns the brush used to paint the document&#39;s background.
Definition: qtextformat.h:345
int columnForDayOfWeek(Qt::DayOfWeek day) const
QString dayName(Qt::DayOfWeek day) const
QTextCharFormat formatForCell(int row, int col) const
QBrush foreground() const
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
Definition: qtextformat.h:352
int column() const
Returns the column this model index refers to.

◆ dateForCell()

QDate QCalendarModel::dateForCell ( int  row,
int  column 
) const

Definition at line 1002 of file qcalendarwidget.cpp.

Referenced by data(), flags(), formatForCell(), QCalendarWidgetPrivate::getCurrentDate(), and QCalendarView::handleMouseEvent().

1003 {
1004  if (row < m_firstRow || row > m_firstRow + RowCount - 1 ||
1005  column < m_firstColumn || column > m_firstColumn + ColumnCount - 1)
1006  return QDate();
1007  const QDate refDate = referenceDate();
1008  if (!refDate.isValid())
1009  return QDate();
1010 
1011  const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate);
1012  if (columnForFirstOfShownMonth - m_firstColumn < MinimumDayOffset)
1013  row -= 1;
1014 
1015  const int requestedDay = 7 * (row - m_firstRow) + column - columnForFirstOfShownMonth - refDate.day() + 1;
1016  return refDate.addDays(requestedDay);
1017 }
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
The QDate class provides date functions.
Definition: qdatetime.h:55
QDate addDays(int days) const
Returns a QDate object containing a date ndays later than the date of this object (or earlier if nday...
Definition: qdatetime.cpp:989
QDate referenceDate() const
int columnForFirstOfMonth(const QDate &date) const

◆ dayName()

QString QCalendarModel::dayName ( Qt::DayOfWeek  day) const

Definition at line 1055 of file qcalendarwidget.cpp.

Referenced by data().

1056 {
1057  switch (m_horizontalHeaderFormat) {
1059  QString standaloneDayName = m_view->locale().standaloneDayName(day, QLocale::NarrowFormat);
1060  if (standaloneDayName == m_view->locale().dayName(day, QLocale::NarrowFormat))
1061  return standaloneDayName.left(1);
1062  return standaloneDayName;
1063  }
1065  return m_view->locale().dayName(day, QLocale::ShortFormat);
1067  return m_view->locale().dayName(day, QLocale::LongFormat);
1068  default:
1069  break;
1070  }
1071  return QString();
1072 }
QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat
QLocale locale() const
QCalendarView * m_view
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
QString dayName(int, FormatType format=LongFormat) const
Returns the localized name of the day (where 1 represents Monday, 2 represents Tuesday and so on)...
Definition: qlocale.cpp:2106
QString standaloneDayName(int, FormatType format=LongFormat) const
Returns the localized name of the day (where 1 represents Monday, 2 represents Tuesday and so on) tha...
Definition: qlocale.cpp:2158

◆ dayOfWeekForColumn()

Qt::DayOfWeek QCalendarModel::dayOfWeekForColumn ( int  section) const

Definition at line 952 of file qcalendarwidget.cpp.

Referenced by data(), and formatForCell().

953 {
954  int col = column - m_firstColumn;
955  if (col < 0 || col > 6)
956  return Qt::Sunday;
957  int day = m_firstDay + col;
958  if (day > 7)
959  day -= 7;
960  return Qt::DayOfWeek(day);
961 }
DayOfWeek
Definition: qnamespace.h:1410
Qt::DayOfWeek m_firstDay

◆ firstColumnDay()

Qt::DayOfWeek QCalendarModel::firstColumnDay ( ) const

Definition at line 1255 of file qcalendarwidget.cpp.

1256 {
1257  return m_firstDay;
1258 }
Qt::DayOfWeek m_firstDay

◆ flags()

Qt::ItemFlags QCalendarModel::flags ( const QModelIndex index) const
virtual

Returns the item flags for the given index.

The base class implementation returns a combination of flags that enables the item (ItemIsEnabled) and allows it to be selected (ItemIsSelectable).

See also
Qt::ItemFlags

Reimplemented from QAbstractItemModel.

Definition at line 1149 of file qcalendarwidget.cpp.

1150 {
1151  QDate date = dateForCell(index.row(), index.column());
1152  if (!date.isValid())
1153  return QAbstractTableModel::flags(index);
1154  if (date < m_minimumDate)
1155  return 0;
1156  if (date > m_maximumDate)
1157  return 0;
1158  return QAbstractTableModel::flags(index);
1159 }
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
The QDate class provides date functions.
Definition: qdatetime.h:55
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
QDate dateForCell(int row, int column) const
int row() const
Returns the row this model index refers to.
int column() const
Returns the column this model index refers to.

◆ formatForCell()

QTextCharFormat QCalendarModel::formatForCell ( int  row,
int  col 
) const

Definition at line 1074 of file qcalendarwidget.cpp.

Referenced by data().

1075 {
1076  QPalette pal;
1078  if (m_view) {
1079  pal = m_view->palette();
1080  if (!m_view->isEnabled())
1081  cg = QPalette::Disabled;
1082  else if (!m_view->isActiveWindow())
1083  cg = QPalette::Inactive;
1084  }
1085 
1087  format.setFont(m_view->font());
1088  bool header = (m_weekNumbersShown && col == HeaderColumn)
1090  format.setBackground(pal.brush(cg, header ? QPalette::AlternateBase : QPalette::Base));
1091  format.setForeground(pal.brush(cg, QPalette::Text));
1092  if (header) {
1093  format.merge(m_headerFormat);
1094  }
1095 
1096  if (col >= m_firstColumn && col < m_firstColumn + ColumnCount) {
1097  Qt::DayOfWeek dayOfWeek = dayOfWeekForColumn(col);
1098  if (m_dayFormats.contains(dayOfWeek))
1099  format.merge(m_dayFormats.value(dayOfWeek));
1100  }
1101 
1102  if (!header) {
1103  QDate date = dateForCell(row, col);
1104  format.merge(m_dateFormats.value(date));
1105  if(date < m_minimumDate || date > m_maximumDate)
1106  format.setBackground(pal.brush(cg, QPalette::Window));
1107  if (m_shownMonth != date.month())
1109  }
1110  return format;
1111 }
QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
QCalendarView * m_view
void setFont(const QFont &font)
Sets the text format&#39;s font.
The QDate class provides date functions.
Definition: qdatetime.h:55
void setBackground(const QBrush &brush)
Sets the brush use to paint the document&#39;s background to the brush specified.
Definition: qtextformat.h:343
bool isActiveWindow() const
DayOfWeek
Definition: qnamespace.h:1410
QMap< Qt::DayOfWeek, QTextCharFormat > m_dayFormats
ColorGroup
Definition: qpalette.h:92
QDate dateForCell(int row, int column) const
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
Qt::DayOfWeek dayOfWeekForColumn(int section) const
const QPalette & palette() const
QMap< QDate, QTextCharFormat > m_dateFormats
bool isEnabled() const
Definition: qwidget.h:948
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
Definition: qtextformat.h:350
const QFont & font() const
QTextCharFormat m_headerFormat
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61

◆ insertColumns()

bool QCalendarModel::insertColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
inlinevirtual

On models that support this, inserts count new columns into the model before the given column.

The items in each new column will be children of the item represented by the parent model index.

If column is 0, the columns are prepended to any existing columns.

If column is columnCount(), the columns are appended to any existing columns.

If parent has no children, a single row with count columns is inserted.

Returns true if the columns were successfully inserted; otherwise returns false.

The base class implementation does nothing and returns false.

If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide your own API for altering the data.

See also
insertRows(), removeColumns(), beginInsertColumns(), endInsertColumns()

Reimplemented from QAbstractItemModel.

Definition at line 834 of file qcalendarwidget.cpp.

835  {
836  beginInsertColumns(parent, column, column + count - 1);
838  return true;
839  }
void beginInsertColumns(const QModelIndex &parent, int first, int last)
Begins a column insertion operation.
void endInsertColumns()
Ends a column insertion operation.

◆ insertRows()

bool QCalendarModel::insertRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
inlinevirtual

On models that support this, inserts count rows into the model before the given row.

Note
The base class implementation of this function does nothing and returns false.

Items in the new row will be children of the item represented by the parent model index.

If row is 0, the rows are prepended to any existing rows in the parent.

If row is rowCount(), the rows are appended to any existing rows in the parent.

If parent has no children, a single column with count rows is inserted.

Returns true if the rows were successfully inserted; otherwise returns false.

If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide your own API for altering the data. In either case, you will need to call beginInsertRows() and endInsertRows() to notify other components that the model has changed.

See also
insertColumns(), removeRows(), beginInsertRows(), endInsertRows()

Reimplemented from QAbstractItemModel.

Definition at line 828 of file qcalendarwidget.cpp.

829  {
830  beginInsertRows(parent, row, row + count - 1);
831  endInsertRows();
832  return true;
833  }
void endInsertRows()
Ends a row insertion operation.
void beginInsertRows(const QModelIndex &parent, int first, int last)
Begins a row insertion operation.

◆ internalUpdate()

void QCalendarModel::internalUpdate ( )

Definition at line 1220 of file qcalendarwidget.cpp.

Referenced by setFirstColumnDay(), setHorizontalHeaderFormat(), setMaximumDate(), setMinimumDate(), setRange(), setWeekNumbersShown(), and showMonth().

1221 {
1222  QModelIndex begin = index(0, 0);
1224  emit dataChanged(begin, end);
1227 }
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the data in row and column with parent.
#define emit
Definition: qobjectdefs.h:76
void headerDataChanged(Qt::Orientation orientation, int first, int last)
This signal is emitted whenever a header is changed.
The QModelIndex class is used to locate data in a data model.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
static const KeyPair *const end

◆ referenceDate()

QDate QCalendarModel::referenceDate ( ) const

Definition at line 985 of file qcalendarwidget.cpp.

Referenced by cellForDate(), and dateForCell().

986 {
987  int refDay = 1;
988  while (refDay <= 31) {
989  QDate refDate(m_shownYear, m_shownMonth, refDay);
990  if (refDate.isValid())
991  return refDate;
992  refDay += 1;
993  }
994  return QDate();
995 }
The QDate class provides date functions.
Definition: qdatetime.h:55

◆ removeColumns()

bool QCalendarModel::removeColumns ( int  column,
int  count,
const QModelIndex parent = QModelIndex() 
)
inlinevirtual

On models that support this, removes count columns starting with the given column under parent parent from the model.

Returns true if the columns were successfully removed; otherwise returns false.

The base class implementation does nothing and returns false.

If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide your own API for altering the data.

See also
removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), endRemoveColumns()

Reimplemented from QAbstractItemModel.

Definition at line 846 of file qcalendarwidget.cpp.

847  {
848  beginRemoveColumns(parent, column, column + count - 1);
850  return true;
851  }
void beginRemoveColumns(const QModelIndex &parent, int first, int last)
Begins a column removal operation.
void endRemoveColumns()
Ends a column removal operation.

◆ removeRows()

bool QCalendarModel::removeRows ( int  row,
int  count,
const QModelIndex parent = QModelIndex() 
)
inlinevirtual

On models that support this, removes count rows starting with the given row under parent parent from the model.

Returns true if the rows were successfully removed; otherwise returns false.

The base class implementation does nothing and returns false.

If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide your own API for altering the data.

See also
removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), endRemoveRows()

Reimplemented from QAbstractItemModel.

Definition at line 840 of file qcalendarwidget.cpp.

841  {
842  beginRemoveRows(parent, row, row + count - 1);
843  endRemoveRows();
844  return true;
845  }
void endRemoveRows()
Ends a row removal operation.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
Begins a row removal operation.

◆ rowCount()

int QCalendarModel::rowCount ( const QModelIndex parent) const
inlinevirtual

Returns the number of rows under the given parent.

When the parent is valid it means that rowCount is returning the number of children of parent.

Note
When implementing a table based model, rowCount() should return 0 when the parent is valid.
See also
columnCount()

Implements QAbstractItemModel.

Definition at line 821 of file qcalendarwidget.cpp.

◆ setDate()

void QCalendarModel::setDate ( const QDate d)

Definition at line 1161 of file qcalendarwidget.cpp.

Referenced by QCalendarWidgetPrivate::_q_slotChangeDate().

1162 {
1163  m_date = d;
1164  if (m_date < m_minimumDate)
1166  else if (m_date > m_maximumDate)
1168 }
double d
Definition: qnumeric_p.h:62

◆ setFirstColumnDay()

void QCalendarModel::setFirstColumnDay ( Qt::DayOfWeek  dayOfWeek)

Definition at line 1246 of file qcalendarwidget.cpp.

1247 {
1248  if (m_firstDay == dayOfWeek)
1249  return;
1250 
1251  m_firstDay = dayOfWeek;
1252  internalUpdate();
1253 }
Qt::DayOfWeek m_firstDay

◆ setHorizontalHeaderFormat()

void QCalendarModel::setHorizontalHeaderFormat ( QCalendarWidget::HorizontalHeaderFormat  format)

Definition at line 1229 of file qcalendarwidget.cpp.

1230 {
1232  return;
1233 
1234  int oldFormat = m_horizontalHeaderFormat;
1236  if (oldFormat == QCalendarWidget::NoHorizontalHeader) {
1237  m_firstRow = 1;
1238  insertRow(0);
1240  m_firstRow = 0;
1241  removeRow(0);
1242  }
1243  internalUpdate();
1244 }
QCalendarWidget::HorizontalHeaderFormat m_horizontalHeaderFormat
bool removeRow(int row, const QModelIndex &parent=QModelIndex())
Removes the given row from the child items of the parent specified.
bool insertRow(int row, const QModelIndex &parent=QModelIndex())
Inserts a single row before the given row in the child items of the parent specified.

◆ setMaximumDate()

void QCalendarModel::setMaximumDate ( const QDate date)

Definition at line 1194 of file qcalendarwidget.cpp.

1195 {
1196  if (!d.isValid() || d == m_maximumDate)
1197  return;
1198 
1199  m_maximumDate = d;
1202  if (m_date > m_maximumDate)
1204  internalUpdate();
1205 }
double d
Definition: qnumeric_p.h:62

◆ setMinimumDate()

void QCalendarModel::setMinimumDate ( const QDate date)

Definition at line 1181 of file qcalendarwidget.cpp.

1182 {
1183  if (!d.isValid() || d == m_minimumDate)
1184  return;
1185 
1186  m_minimumDate = d;
1189  if (m_date < m_minimumDate)
1191  internalUpdate();
1192 }
double d
Definition: qnumeric_p.h:62

◆ setRange()

void QCalendarModel::setRange ( const QDate min,
const QDate max 
)

Definition at line 1207 of file qcalendarwidget.cpp.

1208 {
1209  m_minimumDate = min;
1210  m_maximumDate = max;
1213  if (m_date < m_minimumDate)
1215  if (m_date > m_maximumDate)
1217  internalUpdate();
1218 }
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181

◆ setView()

void QCalendarModel::setView ( QCalendarView view)
inline

Definition at line 876 of file qcalendarwidget.cpp.

877  { m_view = view; }
QCalendarView * m_view

◆ setWeekNumbersShown()

void QCalendarModel::setWeekNumbersShown ( bool  show)

Definition at line 1265 of file qcalendarwidget.cpp.

1266 {
1267  if (m_weekNumbersShown == show)
1268  return;
1269 
1270  m_weekNumbersShown = show;
1271  if (show) {
1272  m_firstColumn = 1;
1273  insertColumn(0);
1274  } else {
1275  m_firstColumn = 0;
1276  removeColumn(0);
1277  }
1278  internalUpdate();
1279 }
bool removeColumn(int column, const QModelIndex &parent=QModelIndex())
Removes the given column from the child items of the parent specified.
bool insertColumn(int column, const QModelIndex &parent=QModelIndex())
Inserts a single column before the given column in the child items of the parent specified.

◆ showMonth()

void QCalendarModel::showMonth ( int  year,
int  month 
)

Definition at line 1170 of file qcalendarwidget.cpp.

Referenced by QCalendarWidgetPrivate::showMonth().

1171 {
1172  if (m_shownYear == year && m_shownMonth == month)
1173  return;
1174 
1175  m_shownYear = year;
1176  m_shownMonth = month;
1177 
1178  internalUpdate();
1179 }

◆ weekNumbersShown()

bool QCalendarModel::weekNumbersShown ( ) const

Definition at line 1260 of file qcalendarwidget.cpp.

1261 {
1262  return m_weekNumbersShown;
1263 }

Properties

◆ m_date

QDate QCalendarModel::m_date

◆ m_dateFormats

QMap<QDate, QTextCharFormat> QCalendarModel::m_dateFormats

Definition at line 894 of file qcalendarwidget.cpp.

Referenced by formatForCell().

◆ m_dayFormats

QMap<Qt::DayOfWeek, QTextCharFormat> QCalendarModel::m_dayFormats

Definition at line 893 of file qcalendarwidget.cpp.

Referenced by formatForCell().

◆ m_firstColumn

int QCalendarModel::m_firstColumn

◆ m_firstDay

Qt::DayOfWeek QCalendarModel::m_firstDay

◆ m_firstRow

int QCalendarModel::m_firstRow

◆ m_headerFormat

QTextCharFormat QCalendarModel::m_headerFormat

Definition at line 895 of file qcalendarwidget.cpp.

Referenced by formatForCell().

◆ m_horizontalHeaderFormat

QCalendarWidget::HorizontalHeaderFormat QCalendarModel::m_horizontalHeaderFormat

◆ m_maximumDate

QDate QCalendarModel::m_maximumDate

◆ m_minimumDate

QDate QCalendarModel::m_minimumDate

◆ m_shownMonth

int QCalendarModel::m_shownMonth

◆ m_shownYear

int QCalendarModel::m_shownYear

◆ m_view

QCalendarView* QCalendarModel::m_view

Definition at line 896 of file qcalendarwidget.cpp.

Referenced by dayName(), formatForCell(), and QCalendarModel().

◆ m_weekNumbersShown

bool QCalendarModel::m_weekNumbersShown

The documentation for this class was generated from the following file: