Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
qtquickcontrols-nemo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
NemoMobile
qtquickcontrols-nemo
Commits
b459ff95
Commit
b459ff95
authored
Oct 29, 2017
by
Chupligin Sergey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CalendarModel] Add fill model function
parent
b2394a98
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
139 deletions
+76
-139
DatePicker.qml
src/controls/DatePicker.qml
+8
-128
calendarmodel.cpp
src/models/calendarmodel.cpp
+45
-2
calendarmodel.h
src/models/calendarmodel.h
+7
-2
models.pro
src/models/models.pro
+11
-3
plugin.cpp
src/models/plugin.cpp
+4
-3
qmldir
src/models/qmldir
+1
-1
No files found.
src/controls/DatePicker.qml
View file @
b459ff95
...
...
@@ -32,6 +32,8 @@
import
QtQuick
2.6
import
QtQuick
.
Controls
.
Nemo
1.0
import
Nemo
.
Models
1.0
Item
{
id
:
datePicker
...
...
@@ -203,7 +205,7 @@ Item {
cellWidth
:
width
/
7
-
1
cellHeight
:
width
/
6
model
:
date
Model
model
:
calendar
Model
delegate
:
Item
{
id
:
dayCell
...
...
@@ -263,138 +265,16 @@ Item {
}
}
}
Component.onCompleted
:
{
dateModel
.
currentDate
=
currentDate
dateModel
.
fillModel
()
}
}
onMonthChanged
:
{
date
Model
.
selectedDate
=
datePicker
.
currentDate
dateModel
.
clear
()
dateModel
.
fillModel
()
calendar
Model
.
selectedDate
=
datePicker
.
currentDate
calendarModel
.
month
=
currentDate
.
getMonth
()
+
1
;
calendarModel
.
year
=
currentDate
.
getFullYear
();
}
ListModel
{
id
:
dateModel
signal
monthChanged
()
property
int
firstDayOffset
:
0
property
date
selectedDate
:
new
Date
()
property
date
currentDate
:
new
Date
()
//public:
function
setEvent
(
eventDate
,
enable
)
{
if
(
eventDate
.
getMonth
()
!==
selectedDate
.
getMonth
()
&&
eventDate
.
getFullYear
()
!==
selectedDate
.
getFullYear
())
return
setProperty
(
eventDate
.
getDate
()
+
firstDayOffset
,
"
hasEventDay
"
,
enable
)
}
function
getMonthYearString
()
{
return
Qt
.
formatDate
(
selectedDate
,
"
MMMM yyyy
"
)
}
function
changeModel
(
_selectedDate
)
{
clear
()
selectedDate
=
_selectedDate
fillModel
()
monthChanged
()
}
function
showNext
()
{
showOtherMonth
(
selectedDate
.
getMonth
()
+
1
)
}
function
showPrevious
()
{
showOtherMonth
(
selectedDate
.
getMonth
()
-
1
)
}
//private:
function
fillModel
()
{
firstDayOffset
=
getFirstDayOffset
(
selectedDate
)
for
(
var
i
=
0
;
i
<
6
*
7
;
++
i
)
{
var
objectDate
=
selectedDate
;
objectDate
.
setDate
(
selectedDate
.
getDate
()
-
(
selectedDate
.
getDate
()
-
1
+
firstDayOffset
-
i
))
appendDayObject
(
objectDate
)
}
}
function
appendDayObject
(
dateOfDay
)
{
append
({
"
dateOfDay
"
:
dateOfDay
,
"
isCurrentDay
"
:
dateOfDay
.
getDate
()
===
currentDate
.
getDate
()
&&
dateOfDay
.
getMonth
()
===
currentDate
.
getMonth
()
&&
dateOfDay
.
getFullYear
()
===
currentDate
.
getFullYear
(),
"
isOtherMonthDay
"
:
dateOfDay
.
getMonth
()
!==
selectedDate
.
getMonth
(),
"
hasEventDay
"
:
false
})
}
function
showOtherMonth
(
month
)
{
var
newDate
=
selectedDate
var
currentDay
=
selectedDate
.
getDate
()
currentDay
=
getValidDayByMonthAndDay
(
month
,
currentDay
,
isLeapYear
(
selectedDate
.
getFullYear
()));
newDate
.
setMonth
(
month
,
currentDay
)
changeModel
(
newDate
)
}
function
getFirstDayOffset
(
currentDate
)
{
var
tmpDate
=
currentDate
tmpDate
.
setDate
(
currentDate
.
getDate
()
-
(
currentDate
.
getDate
()
-
1
))
var
firstDayWeekDay
=
tmpDate
.
getDay
()
if
(
firstDayWeekDay
===
0
)
firstDayWeekDay
=
6
else
firstDayWeekDay
--
return
firstDayWeekDay
}
function
getValidDayByMonthAndDay
(
month
,
day
,
leapYear
)
{
if
(
month
===
12
)
month
=
0
if
(
month
===
-
1
)
month
=
11
if
(
month
===
0
||
month
===
2
||
month
===
4
||
month
===
6
||
month
===
7
||
month
===
9
||
month
===
11
)
return
day
if
(
month
!==
1
)
{
if
(
day
<
31
)
return
day
return
30
}
if
(
day
<
29
)
return
day
if
(
leapYear
)
return
29
return
28
}
function
isLeapYear
(
year
)
{
if
(
year
%
4
===
0
)
{
if
(
year
%
100
===
0
)
{
if
(
year
%
400
===
0
)
{
return
true
;
}
else
return
false
;
}
else
return
true
;
}
return
false
;
}
CalendarModel
{
id
:
calendarModel
}
}
src/models/calendarmodel.cpp
View file @
b459ff95
...
...
@@ -68,7 +68,7 @@ QVariant CalendarModel::data(const QModelIndex &index, int role) const
return
QVariant
();
}
d
ateItem
item
=
m_dateList
.
at
(
index
.
row
());
D
ateItem
item
=
m_dateList
.
at
(
index
.
row
());
switch
(
role
)
{
case
Qt
:
:
UserRole
:
...
...
@@ -94,7 +94,7 @@ QVariant CalendarModel::get(const int idx) const
}
QMap
<
QString
,
QVariant
>
itemData
;
d
ateItem
item
=
m_dateList
.
at
(
idx
);
D
ateItem
item
=
m_dateList
.
at
(
idx
);
itemData
.
insert
(
"isOtherMonthDay"
,
item
.
isOtherMonthDay
);
itemData
.
insert
(
"isCurrentDay"
,
item
.
isCurrentDay
);
...
...
@@ -136,5 +136,48 @@ void CalendarModel::setYear(int year)
void
CalendarModel
::
fill
()
{
m_dateList
.
clear
();
QDate
firstDayOfSelectedMonth
=
QDate
(
m_year
,
m_month
,
1
);
int
startWeekDay
=
firstDayOfSelectedMonth
.
dayOfWeek
();
/*If first dayof moth not Monday add form preview month*/
if
(
startWeekDay
!=
1
)
{
int
needToAdd
=
1
-
startWeekDay
;
for
(
int
n
=
needToAdd
;
n
<
0
;
n
++
)
{
m_dateList
.
append
(
createDateItem
(
firstDayOfSelectedMonth
.
addDays
(
n
),
true
));
}
}
for
(
int
n
=
0
;
n
<
firstDayOfSelectedMonth
.
daysInMonth
();
n
++
)
{
QDate
date
=
firstDayOfSelectedMonth
.
addDays
(
n
);
m_dateList
.
append
(
createDateItem
(
date
,
false
,
date
==
m_currentDate
));
}
/*if last day of moth not Sunday add from next mont*/
QDate
lastDayOfSelectedMonth
=
QDate
(
m_year
,
m_month
,
firstDayOfSelectedMonth
.
daysInMonth
());
int
endWeekDay
=
lastDayOfSelectedMonth
.
dayOfWeek
();
if
(
endWeekDay
!=
7
)
{
int
needToAdd
=
7
-
endWeekDay
;
for
(
int
n
=
1
;
n
<=
needToAdd
;
n
++
)
{
m_dateList
.
append
(
createDateItem
(
lastDayOfSelectedMonth
.
addDays
(
n
),
true
));
}
}
dataChanged
(
createIndex
(
0
,
0
),
createIndex
(
rowCount
()
-
1
,
0
));
}
CalendarModel
::
DateItem
CalendarModel
::
createDateItem
(
QDate
dateOfDay
,
bool
isOtherMonthDay
,
bool
isCurrentDay
,
bool
isSelectedDay
,
bool
hasEventDay
)
{
DateItem
dateItem
;
dateItem
.
dateOfDay
=
dateOfDay
;
dateItem
.
hasEventDay
=
hasEventDay
;
dateItem
.
isCurrentDay
=
isCurrentDay
;
dateItem
.
isOtherMonthDay
=
isOtherMonthDay
;
dateItem
.
isSelectedDay
=
isSelectedDay
;
return
dateItem
;
}
src/models/calendarmodel.h
View file @
b459ff95
...
...
@@ -38,7 +38,7 @@
class
CalendarModel
:
public
QAbstractListModel
{
Q_OBJECT
struct
d
ateItem
{
struct
D
ateItem
{
bool
isOtherMonthDay
;
bool
isCurrentDay
;
bool
isSelectedDay
;
...
...
@@ -76,9 +76,14 @@ signals:
private:
QHash
<
int
,
QByteArray
>
m_hash
;
QList
<
d
ateItem
>
m_dateList
;
QList
<
D
ateItem
>
m_dateList
;
void
fill
();
DateItem
createDateItem
(
QDate
dateOfDay
,
bool
isOtherMonthDay
=
false
,
bool
isCurrentDay
=
false
,
bool
isSelectedDay
=
false
,
bool
hasEventDay
=
false
);
QDate
m_currentDate
;
QDate
m_selectedDate
;
...
...
src/models/models.pro
View file @
b459ff95
TEMPLATE
=
lib
TARGET
=
nemomodels
plugin
TARGET
=
nemomodels
PLUGIN_IMPORT_PATH
=
Nemo
/
Models
QT
-=
gui
QT
+=
qml
CONFIG
+=
qt
plugin
hide_symbols
SOURCES
+=
\
...
...
@@ -11,9 +15,13 @@ SOURCES += \
HEADERS
+=
\
calendarmodel
.
h
target
.
path
=
/
usr
/
lib
/
qt5
/
qml
/
org
/
nemomobile
/
models
/
target
.
path
=
$$
[
QT_INSTALL_QML
]
/
$$
PLUGIN_IMPORT_PATH
qmlfiles
.
files
=
\
qmldir
qmlfiles
.
path
=
$$
[
QT_INSTALL_QML
]
/
$$
PLUGIN_IMPORT_PATH
INSTALLS
+=
target
INSTALLS
+=
target
qmlfiles
DISTFILES
+=
\
qmldir
src/models/plugin.cpp
View file @
b459ff95
...
...
@@ -27,18 +27,19 @@
class
Q_DECL_EXPORT
NemoSettingsPlugin
:
public
QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA
(
IID
"org.nemomobile.models"
)
Q_PLUGIN_METADATA
(
IID
"Nemo.Models"
)
public:
virtual
~
NemoSettingsPlugin
()
{
}
void
initializeEngine
(
QQmlEngine
*
,
const
char
*
uri
)
{
Q_ASSERT
(
uri
==
QLatin1String
(
"org.nemomobile.models"
));
Q_ASSERT
(
uri
==
QLatin1String
(
"
Nemo.Models"
)
||
uri
==
QLatin1String
(
"
org.nemomobile.models"
));
}
void
registerTypes
(
const
char
*
uri
)
{
Q_ASSERT
(
uri
==
QLatin1String
(
"org.nemomobile.models"
));
Q_ASSERT
(
uri
==
QLatin1String
(
"
Nemo.Models"
)
||
uri
==
QLatin1String
(
"
org.nemomobile.models"
));
qmlRegisterType
<
CalendarModel
>
(
uri
,
1
,
0
,
"CalendarModel"
);
}
};
...
...
src/models/qmldir
View file @
b459ff95
module
org.nemomobile.m
odels
module
Nemo.M
odels
plugin nemomodels
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment