Commit 847eb1fb authored by Chupligin Sergey's avatar Chupligin Sergey

[DatePicker] add datelistmodel proto

parent 4df4d8f1
...@@ -39,7 +39,8 @@ HEADERS += \ ...@@ -39,7 +39,8 @@ HEADERS += \
themedaemon/mlocalthemedaemonclient.h \ themedaemon/mlocalthemedaemonclient.h \
themedaemon/mabstractthemedaemonclient.h \ themedaemon/mabstractthemedaemonclient.h \
sizing.h \ sizing.h \
theme.h theme.h \
datelistmodel.h
SOURCES += \ SOURCES += \
qquicknemocontrolsextensionplugin.cpp \ qquicknemocontrolsextensionplugin.cpp \
...@@ -51,7 +52,8 @@ SOURCES += \ ...@@ -51,7 +52,8 @@ SOURCES += \
themedaemon/mlocalthemedaemonclient.cpp \ themedaemon/mlocalthemedaemonclient.cpp \
themedaemon/mabstractthemedaemonclient.cpp \ themedaemon/mabstractthemedaemonclient.cpp \
sizing.cpp \ sizing.cpp \
theme.cpp theme.cpp \
datelistmodel.cpp
target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
......
/****************************************************************************************
**
** Copyright (C) 2017 Chupligin Sergey <neochapay@gmail.com>
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the author nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
#include "datelistmodel.h"
DateListModel::DateListModel(QObject *parent) :
QAbstractListModel(parent)
{
m_hash.insert(Qt::UserRole ,QByteArray("isOtherMonthDay"));
m_hash.insert(Qt::UserRole+1 ,QByteArray("isCurrentDay"));
m_hash.insert(Qt::UserRole+2 ,QByteArray("isSelectedDay"));
m_hash.insert(Qt::UserRole+3 ,QByteArray("hasEventDay"));
m_hash.insert(Qt::UserRole+4 ,QByteArray("dateOfDay"));
m_currentDate = QDate::currentDate();
m_year = m_currentDate.year();
m_month = m_currentDate.month();
fill();
}
int DateListModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_dateList.count();
}
QVariant DateListModel::data(const QModelIndex &index, int role) const
{
Q_UNUSED(role);
if(!index.isValid())
{
return QVariant();
}
if(index.row() >= m_dateList.size())
{
return QVariant();
}
dateItem item = m_dateList.at(index.row());
switch (role)
{
case Qt::UserRole:
return item.isOtherMonthDay;
case Qt::UserRole+1:
return item.isCurrentDay;
case Qt::UserRole+2:
return item.isSelectedDay;
case Qt::UserRole+3:
return item.hasEventDay;
case Qt::UserRole+4:
return item.dateOfDay;
default:
return QVariant();
}
}
QVariant DateListModel::get(const int idx)
{
if(idx >= m_dateList.size())
{
return QVariant();
}
QMap<QString, QVariant> itemData;
dateItem item = m_dateList.at(idx);
itemData.insert("isOtherMonthDay",item.isOtherMonthDay);
itemData.insert("isCurrentDay",item.isCurrentDay);
itemData.insert("isSelectedDay",item.isSelectedDay);
itemData.insert("hasEventDay",item.hasEventDay);
itemData.insert("dateOfDay",item.dateOfDay);
return QVariant(itemData);
}
void DateListModel::setSelectedDate(QDate date)
{
if(m_selectedDate != date)
{
m_selectedDate = date;
emit selectedDateChanged();
}
}
void DateListModel::setMonth(int month)
{
if(m_month != month && month > 0 && month < 13)
{
m_month = month;
fill();
emit monthChanged();
}
}
void DateListModel::setYear(int year)
{
if(m_year != year)
{
m_year = year;
fill();
emit yearChanged();
}
}
void DateListModel::fill()
{
}
/****************************************************************************************
**
** Copyright (C) 2017 Chupligin Sergey <neochapay@gmail.com>
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the author nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
****************************************************************************************/
#ifndef DATELISTMODEL_H
#define DATELISTMODEL_H
#include <QAbstractListModel>
#include <QDate>
class DateListModel : public QAbstractListModel
{
Q_OBJECT
struct dateItem{
bool isOtherMonthDay;
bool isCurrentDay;
bool isSelectedDay;
bool hasEventDay;
QDate dateOfDay;
};
Q_PROPERTY(QDate currentDate READ currentDate)
Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged)
Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged)
Q_PROPERTY(QDate selectedDate READ selectedDate WRITE setSelectedDate NOTIFY selectedDateChanged)
public:
explicit DateListModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QHash<int, QByteArray> roleNames() const {return m_hash;}
void setSelectedDate(QDate date);
void setMonth(int month);
void setYear(int year);
QDate currentDate(){return m_currentDate;}
QDate selectedDate(){return m_selectedDate;}
int month(){return m_month;}
int year(){return m_year;}
public slots:
QVariant get(const int idx);
signals:
void selectedDateChanged();
void monthChanged();
void yearChanged();
private:
QHash<int,QByteArray> m_hash;
QList<dateItem> m_dateList;
void fill();
QDate m_currentDate;
QDate m_selectedDate;
int m_month;
int m_year;
};
#endif // DATELISTMODEL_H
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "nemoimageprovider.h" #include "nemoimageprovider.h"
#include "sizing.h" #include "sizing.h"
#include "theme.h" #include "theme.h"
#include "datelistmodel.h"
QQuickNemoControlsExtensionPlugin::QQuickNemoControlsExtensionPlugin(QObject *parent) : QQuickNemoControlsExtensionPlugin::QQuickNemoControlsExtensionPlugin(QObject *parent) :
QQmlExtensionPlugin(parent) QQmlExtensionPlugin(parent)
...@@ -46,6 +47,7 @@ void QQuickNemoControlsExtensionPlugin::registerTypes(const char *uri) ...@@ -46,6 +47,7 @@ void QQuickNemoControlsExtensionPlugin::registerTypes(const char *uri)
qmlRegisterType<NemoWindow>(uri, 1, 0, "NemoWindow"); qmlRegisterType<NemoWindow>(uri, 1, 0, "NemoWindow");
qmlRegisterType<NemoPage>(uri, 1, 0, "NemoPage"); qmlRegisterType<NemoPage>(uri, 1, 0, "NemoPage");
qmlRegisterType<QQuickFilteringMouseArea>(uri, 1, 0, "FilteringMouseArea"); qmlRegisterType<QQuickFilteringMouseArea>(uri, 1, 0, "FilteringMouseArea");
qmlRegisterType<DateListModel>(uri, 1, 0, "NemoDateListModel");
} }
void QQuickNemoControlsExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri) void QQuickNemoControlsExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment