#include "p_city.h"
#include "ui_p_city.h"
#include <QDebug>
#include <QButtonGroup>
#include <QSet>
QStyleOption opt;
//p_citynum是当前页所选的城市数目2
//City_Num是总城市数目
//Cur_pro是当前所选的省份的名字1
//QP_city是1对2
P_City::P_City(QWidget *parent) :
QWidget(parent),
ui(new Ui::P_City)
{
ui->setupUi(this);
this->setWindowTitle("请选择你去过的城市");
//int CityNum = 0;
ui->label->setText(QString::number(0, 10));
ui->label_2->setText(QString::number(0, 10));
QButtonGroup *buttongroup = new QButtonGroup();
//热门,以下将按钮装入buttongroup里,统一进行操作
buttongroup->addButton(ui->beijing, 0);
buttongroup->addButton(ui->shanghai, 1);
buttongroup->addButton(ui->tianjin, 2);
buttongroup->addButton(ui->chongqing, 3);
buttongroup->addButton(ui->xianggang, 4);
buttongroup->addButton(ui->aomen, 5);
buttongroup->addButton(ui->tianjin, 2);
buttongroup->addButton(ui->chongqing, 3);
buttongroup->addButton(ui->xianggang, 4);
buttongroup->addButton(ui->aomen, 5);
//江苏
buttongroup->addButton(ui->nanjing, 0);
buttongroup->addButton(ui->xuzhou, 1);
buttongroup->addButton(ui->lianyungang, 2);
buttongroup->addButton(ui->suqian, 3);
buttongroup->addButton(ui->huaian, 4);
buttongroup->addButton(ui->yancheng, 5);
buttongroup->addButton(ui->yangzhou, 0);
buttongroup->addButton(ui->taizhou, 1);
//浙江
buttongroup->addButton(ui->hangzhou, 2);
buttongroup->addButton(ui->ningbo, 3);
buttongroup->addButton(ui->huzhou, 4);
buttongroup->addButton(ui->jiaxing, 5);
buttongroup->addButton(ui->zhoushan, 0);
buttongroup->addButton(ui->shaoxing, 1);
buttongroup->addButton(ui->quzhou, 2);
buttongroup->addButton(ui->jinhua, 3);
buttongroup->addButton(ui->taizhou, 4);
//安徽
buttongroup->addButton(ui->hefei, 5);
buttongroup->addButton(ui->wuhu, 0);
buttongroup->addButton(ui->bengbu, 1);
buttongroup->addButton(ui->huainan, 2);
buttongroup->addButton(ui->maanshan, 3);
buttongroup->addButton(ui->huaibei, 4);
buttongroup->addButton(ui->tongling, 5);
buttongroup->addButton(ui->anqing, 0);
//海南
buttongroup->addButton(ui->haikou, 1);
buttongroup->addButton(ui->sanya, 2);
buttongroup->addButton(ui->wenchang, 3);
buttongroup->addButton(ui->qionghai, 4);
buttongroup->addButton(ui->wanning, 5);
buttongroup->addButton(ui->dongfang, 0);
buttongroup->addButton(ui->wuzhishan, 1);
buttongroup->addButton(ui->nansha, 2);
//四川
buttongroup->addButton(ui->chengdu, 3);
buttongroup->addButton(ui->guangyuan, 4);
buttongroup->addButton(ui->mianyang, 5);
buttongroup->addButton(ui->deyang, 0);
buttongroup->addButton(ui->nanchong, 1);
buttongroup->addButton(ui->guangan, 2);
buttongroup->addButton(ui->suining, 3);
buttongroup->addButton(ui->neijiang, 4);
//云南
buttongroup->addButton(ui->kunming, 5);
buttongroup->addButton(ui->qujing, 0);
buttongroup->addButton(ui->yuxi, 1);
buttongroup->addButton(ui->lijiang, 2);
buttongroup->addButton(ui->zhaotong, 3);
buttongroup->addButton(ui->simao, 4);
buttongroup->addButton(ui->lincang, 5);
buttongroup->addButton(ui->baoshan, 0);
//河南
buttongroup->addButton(ui->zhengzhou, 1);
buttongroup->addButton(ui->kaifeng, 2);
buttongroup->addButton(ui->luoyang, 3);
buttongroup->addButton(ui->pingdingshan, 4);
buttongroup->addButton(ui->anyang, 5);
buttongroup->addButton(ui->hebi, 2);
buttongroup->addButton(ui->xinxiang, 3);
buttongroup->addButton(ui->jiaozhuo, 4);
//山东
buttongroup->addButton(ui->jinan, 5);
buttongroup->addButton(ui->qingdao, 0);
buttongroup->addButton(ui->liaocheng, 1);
buttongroup->addButton(ui->dezhou, 2);
buttongroup->addButton(ui->dongying, 3);
buttongroup->addButton(ui->zibo, 4);
buttongroup->addButton(ui->weifang, 5);
buttongroup->addButton(ui->yantai, 0);
//河北
buttongroup->addButton(ui->shijiazhuang, 0);
buttongroup->addButton(ui->handan, 0);
buttongroup->addButton(ui->tangshan,0);
buttongroup->addButton(ui->baoding, 0);
buttongroup->addButton(ui->qinhuangdao, 0);
buttongroup->addButton(ui->xingtai, 0);
buttongroup->addButton(ui->zhangjiakou, 0);
buttongroup->addButton(ui->chengde, 0);
//山西
buttongroup->addButton(ui->taiyuan,1);
buttongroup->addButton(ui->datong, 4);
buttongroup->addButton(ui->shuozhou,5);
buttongroup->addButton(ui->yangquan, 0);
buttongroup->addButton(ui->changzhi,1);
buttongroup->addButton(ui->jincheng,2);
buttongroup->addButton(ui->yizhou1, 3);
buttongroup->addButton(ui->lvliang, 4);
//陕西
buttongroup->addButton(ui->xian, 5);
buttongroup->addButton(ui->yanan, 0);
buttongroup->addButton(ui->tongchuan,1);
buttongroup->addButton(ui->weinan, 2);
buttongroup->addButton(ui->xianyang,3);
buttongroup->addButton(ui->baoji, 4);
buttongroup->addButton(ui->hanzhong,5);
buttongroup->addButton(ui->yulin, 0);
Cur_pro = ui->remen->text();//初始化当前省份
connect(ui->remen,&QPushButton::clicked,this,&P_City::switchPage);//每一个省对应一页
connect(ui->jiangsu,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->zhejiang,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->anhui,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->hainan,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->sichuan,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->yunnan,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->henan,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->sandong,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->hebei,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->shanxi,&QPushButton::clicked,this,&P_City::switchPage);
connect(ui->sanxixi,&QPushButton::clicked,this,&P_City::switchPage);
//connect(ui->remen,SIGNAL(showmap()),this,SLOT(add()));
//QList<QAbstractButton*> buttonsList = buttonGroup->buttons();
//foreach (QAbstractButton *button, buttonsList)
//{
// if(button->)
// }
//连接槽函数统一操作
connect(buttongroup, SIGNAL(buttonClicked(QAbstractButton*)),this,SLOT(add(QAbstractButton*)));
}
P_City::~P_City()
{
delete ui;
}
void P_City::receivecity()
{
this->show();
}
void P_City::receivemapp()
{
this->show();
}
void P_City::add(QAbstractButton* button)
{
//QString title = ui->remen->text();
if(Qflag[button]==1)//点击了两次
Qflag[button] = 0;
else if(Qflag[button]==0)
Qflag[button] = 1;
if(Qflag[button]==1)//点击一次
{
CityNum++;
p_citynum++;
City.insert(button->text());
button->setStyleSheet("background-color: rgb(255, 255, 224)");//变色
}
else if(Qflag[button]==0)//QString::number(CityNum, 10)
{
CityNum--;
p_citynum--;
City.remove(button->text());
button->setStyleSheet("background-color: rgb(255, 255, 204");
button->setChecked(false);
}
QString city = button->text();
//qDebug() << city.toStdString().c_str();
//qDebug("%s\n", button->text());
ui->label_2->setText(QString::number(p_citynum, 10));
ui->label->setText(QString::number(CityNum, 10));
//button->setStyleSheet("background-color: rgb(255, 255, 224");
//qDebug("%d\n", CityNum);
if(p_citynum && !Pro.contains(Cur_pro))//判断是否保存当前省份名称
{
Pro.insert(Cur_pro);
}
else if(!p_citynum && Pro.contains(Cur_pro))