Skip to content

Commit

Permalink
Update menu is ok
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Apr 18, 2019
1 parent e1724fe commit 163a291
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion App/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ MainWindow::MainWindow(QWidget *parent) :
// m_pLunarCalendar->SetShowTools(false);
// m_pLunarCalendar->SetSelectedDate(QDate::currentDate());
// m_pLunarCalendar->SetShowGrid(true);
m_pLunarCalendar->SetDateRange(QDate(2000, 1, 1), QDate(2000, 2, 1));
m_pLunarCalendar->SetDateRange(QDate(2002, 12, 30), QDate(2003, 2, 1));
// m_pLunarCalendar->GenerateCalendarTable(qApp->applicationDirPath() + QDir::separator() + "cache.dat");
// m_pLunarCalendar->LoadCalendarTable(qApp->applicationDirPath() + QDir::separator() + "cache.dat");
// m_pLunarCalendar->SetShowWeekHead(false);
Expand Down
56 changes: 28 additions & 28 deletions Src/LunarCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ void CLunarCalendar::SetDateRange(const QDate &min, const QDate &max)
if (!min.isValid() || !max.isValid())
return;

if(min > max)
{
qCritical() << "SetDateRange parmter error: min =" << min << " max =" << max;
return;
}

CLunarCalendarModel* pModel = dynamic_cast<CLunarCalendarModel*>(ui->tvMonth->model());
if(!pModel) return;
if(pModel->GetMaximumDate() == max && pModel->GetMinimumDate() == min)
Expand Down Expand Up @@ -466,32 +472,35 @@ int CLunarCalendar::EnableMonthMenu()
CLunarCalendarModel* pModel = dynamic_cast<CLunarCalendarModel*>(ui->tvMonth->model());
if(!pModel) return -1;

if (pModel->GetShowYear() == pModel->GetMinimumDate().year()) {
int minYear = pModel->GetMinimumDate().year();
int maxYear = pModel->GetMaximumDate().year();
if (GetViewType() == ViewTypeWeek) {
pModel->GetMinimumDate().weekNumber(&minYear);
pModel->GetMaximumDate().weekNumber(&maxYear);
}

if (pModel->GetShowYear() == minYear) {
switch (GetViewType())
{
case ViewTypeMonth:
if (pModel->GetShowMonth() == pModel->GetMinimumDate().month())
prevEnabled = false;
break;
case ViewTypeWeek:
int year = 0;
if (pModel->GetShowWeek() == pModel->GetMinimumDate().weekNumber(&year)
&& pModel->GetMinimumDate().year() == year)
if (pModel->GetShowWeek() == pModel->GetMinimumDate().weekNumber())
prevEnabled = false;
break;
}
}

if (pModel->GetShowYear() == pModel->GetMaximumDate().year()) {
if (pModel->GetShowYear() == maxYear) {
switch (GetViewType()) {
case ViewTypeMonth:
if (pModel->GetShowMonth() == pModel->GetMaximumDate().month())
nextEnabled = false;
break;
case ViewTypeWeek:
int year = 0;
if(pModel->GetShowWeek() == pModel->GetMaximumDate().weekNumber(&year)
&& pModel->GetMaximumDate().year() == year)
if(pModel->GetShowWeek() == pModel->GetMaximumDate().weekNumber())
nextEnabled = false;
break;
}
Expand All @@ -510,44 +519,35 @@ int CLunarCalendar::UpdateMonthMenu()
if(!pModel) return -1;

EnableMonthMenu();

switch (GetViewType()) {
case ViewTypeMonth:
beg = 1;
end = 12;
break;
case ViewTypeWeek:
beg = 1;

int minYear = pModel->GetMinimumDate().year();
int maxYear = pModel->GetMaximumDate().year();

if (GetViewType() == ViewTypeWeek) {
end = pModel->GetWeeksOfYear(ui->spYear->value());
pModel->GetMinimumDate().weekNumber(&minYear);
pModel->GetMaximumDate().weekNumber(&maxYear);
}

if (pModel->GetShowYear() == pModel->GetMinimumDate().year()) {
if (pModel->GetShowYear() == minYear) {
switch (GetViewType())
{
case ViewTypeMonth:
beg = pModel->GetMinimumDate().month();
break;
case ViewTypeWeek:
int year = 0;
beg = pModel->GetMinimumDate().weekNumber(&year);
if(pModel->GetMinimumDate().year() != year)
{
beg = 1;
}
beg = pModel->GetMinimumDate().weekNumber();
break;
}
}

if (pModel->GetShowYear() == pModel->GetMaximumDate().year()) {
if (pModel->GetShowYear() == maxYear) {
switch (GetViewType()) {
case ViewTypeMonth:
end = pModel->GetMaximumDate().month();
break;
case ViewTypeWeek:
int year = 0;
end = pModel->GetMaximumDate().weekNumber(&year);
if(pModel->GetMaximumDate().year() < year)
end = pModel->GetMaximumDate().addDays(-7).weekNumber();
end = pModel->GetMaximumDate().weekNumber();
break;
}
}
Expand Down

0 comments on commit 163a291

Please sign in to comment.