"Fossies" - the Fresh Open Source Software Archive

Member "fet-5.47.1/src/interface/buildingsform.cpp" (20 Jul 2018, 9372 Bytes) of package /linux/privat/fet-5.47.1.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "buildingsform.cpp" see the Fossies "Dox" file reference documentation.

    1 //
    2 //
    3 // Description: This file is part of FET
    4 //
    5 //
    6 // Author: Liviu Lalescu <Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)>
    7 // Copyright (C) 2003 Liviu Lalescu <https://lalescu.ro/liviu/>
    8 //
    9 
   10 /***************************************************************************
   11  *                                                                         *
   12  *   This program is free software: you can redistribute it and/or modify  *
   13  *   it under the terms of the GNU Affero General Public License as        *
   14  *   published by the Free Software Foundation, either version 3 of the    *
   15  *   License, or (at your option) any later version.                       *
   16  *                                                                         *
   17  ***************************************************************************/
   18 
   19 #include "timetable_defs.h"
   20 #include "fet.h"
   21 #include "buildingsform.h"
   22 #include "addbuildingform.h"
   23 #include "modifybuildingform.h"
   24 
   25 #include <QMessageBox>
   26 
   27 #include <QListWidget>
   28 #include <QScrollBar>
   29 #include <QAbstractItemView>
   30 
   31 #include <QSplitter>
   32 #include <QSettings>
   33 #include <QObject>
   34 #include <QMetaObject>
   35 
   36 extern const QString COMPANY;
   37 extern const QString PROGRAM;
   38 
   39 extern bool students_schedule_ready;
   40 extern bool rooms_schedule_ready;
   41 extern bool teachers_schedule_ready;
   42 
   43 BuildingsForm::BuildingsForm(QWidget* parent): QDialog(parent)
   44 {
   45     setupUi(this);
   46     
   47     currentBuildingTextEdit->setReadOnly(true);
   48 
   49     modifyBuildingPushButton->setDefault(true);
   50 
   51     buildingsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
   52 
   53     connect(addBuildingPushButton, SIGNAL(clicked()), this, SLOT(addBuilding()));
   54     connect(removeBuildingPushButton, SIGNAL(clicked()), this, SLOT(removeBuilding()));
   55     connect(buildingsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(buildingChanged(int)));
   56     connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
   57     connect(modifyBuildingPushButton, SIGNAL(clicked()), this, SLOT(modifyBuilding()));
   58 
   59     connect(moveBuildingUpPushButton, SIGNAL(clicked()), this, SLOT(moveBuildingUp()));
   60     connect(moveBuildingDownPushButton, SIGNAL(clicked()), this, SLOT(moveBuildingDown()));
   61 
   62     connect(sortBuildingsPushButton, SIGNAL(clicked()), this, SLOT(sortBuildings()));
   63     connect(buildingsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyBuilding()));
   64 
   65     connect(commentsPushButton, SIGNAL(clicked()), this, SLOT(comments()));
   66 
   67     centerWidgetOnScreen(this);
   68     restoreFETDialogGeometry(this);
   69     //restore splitter state
   70     QSettings settings(COMPANY, PROGRAM);
   71     if(settings.contains(this->metaObject()->className()+QString("/splitter-state")))
   72         splitter->restoreState(settings.value(this->metaObject()->className()+QString("/splitter-state")).toByteArray());
   73     
   74     this->filterChanged();
   75 }
   76 
   77 BuildingsForm::~BuildingsForm()
   78 {
   79     saveFETDialogGeometry(this);
   80     //save splitter state
   81     QSettings settings(COMPANY, PROGRAM);
   82     settings.setValue(this->metaObject()->className()+QString("/splitter-state"), splitter->saveState());
   83 }
   84 
   85 bool BuildingsForm::filterOk(Building* bu)
   86 {
   87     Q_UNUSED(bu);
   88 
   89     bool ok=true;
   90 
   91     return ok;
   92 }
   93 
   94 void BuildingsForm::filterChanged()
   95 {
   96     QString s;
   97     buildingsListWidget->clear();
   98     visibleBuildingsList.clear();
   99     for(int i=0; i<gt.rules.buildingsList.size(); i++){
  100         Building* bu=gt.rules.buildingsList[i];
  101         if(this->filterOk(bu)){
  102             s=bu->name;
  103             visibleBuildingsList.append(bu);
  104             buildingsListWidget->addItem(s);
  105         }
  106     }
  107     
  108     if(buildingsListWidget->count()>0)
  109         buildingsListWidget->setCurrentRow(0);
  110     else
  111         buildingChanged(-1);
  112 }
  113 
  114 void BuildingsForm::addBuilding()
  115 {
  116     AddBuildingForm addBuildingForm(this);
  117     setParentAndOtherThings(&addBuildingForm, this);
  118     addBuildingForm.exec();
  119     
  120     filterChanged();
  121     
  122     buildingsListWidget->setCurrentRow(buildingsListWidget->count()-1);
  123 }
  124 
  125 void BuildingsForm::removeBuilding()
  126 {
  127     int ind=buildingsListWidget->currentRow();
  128     if(ind<0){
  129         QMessageBox::information(this, tr("FET information"), tr("Invalid selected building"));
  130         return;
  131     }
  132     
  133     Building* bu=visibleBuildingsList.at(ind);
  134     assert(bu!=NULL);
  135 
  136     if(QMessageBox::warning( this, tr("FET"),
  137         tr("Are you sure you want to delete this building?"),
  138         tr("Yes"), tr("No"), 0, 0, 1 ) == 1)
  139         return;
  140         
  141     bool tmp=gt.rules.removeBuilding(bu->name);
  142     assert(tmp);
  143     
  144     visibleBuildingsList.removeAt(ind);
  145     buildingsListWidget->setCurrentRow(-1);
  146     QListWidgetItem* item=buildingsListWidget->takeItem(ind);
  147     delete item;
  148     
  149     if(ind>=buildingsListWidget->count())
  150         ind=buildingsListWidget->count()-1;
  151     if(ind>=0)
  152         buildingsListWidget->setCurrentRow(ind);
  153     else
  154         currentBuildingTextEdit->setPlainText(QString(""));
  155 }
  156 
  157 void BuildingsForm::buildingChanged(int index)
  158 {
  159     if(index<0){
  160         currentBuildingTextEdit->setPlainText("");
  161         return;
  162     }
  163 
  164     QString s;
  165     Building* building=visibleBuildingsList.at(index);
  166 
  167     assert(building!=NULL);
  168     s=building->getDetailedDescriptionWithConstraints(gt.rules);
  169     currentBuildingTextEdit->setPlainText(s);
  170 }
  171 
  172 void BuildingsForm::moveBuildingUp()
  173 {
  174     if(buildingsListWidget->count()<=1)
  175         return;
  176     int i=buildingsListWidget->currentRow();
  177     if(i<0 || i>=buildingsListWidget->count())
  178         return;
  179     if(i==0)
  180         return;
  181         
  182     QString s1=buildingsListWidget->item(i)->text();
  183     QString s2=buildingsListWidget->item(i-1)->text();
  184     
  185     Building* bu1=gt.rules.buildingsList.at(i);
  186     Building* bu2=gt.rules.buildingsList.at(i-1);
  187     
  188     gt.rules.internalStructureComputed=false;
  189     setRulesModifiedAndOtherThings(&gt.rules);
  190     
  191     teachers_schedule_ready=false;
  192     students_schedule_ready=false;
  193     rooms_schedule_ready=false;
  194 
  195     buildingsListWidget->item(i)->setText(s2);
  196     buildingsListWidget->item(i-1)->setText(s1);
  197     
  198     gt.rules.buildingsList[i]=bu2;
  199     gt.rules.buildingsList[i-1]=bu1;
  200     
  201     //Begin bug fix on 2017-08-29
  202     Building* vb1=visibleBuildingsList[i];
  203     Building* vb2=visibleBuildingsList[i-1];
  204     visibleBuildingsList[i]=vb2;
  205     visibleBuildingsList[i-1]=vb1;
  206     //End bug fix
  207     
  208     buildingsListWidget->setCurrentRow(i-1);
  209     buildingChanged(i-1);
  210 }
  211 
  212 void BuildingsForm::moveBuildingDown()
  213 {
  214     if(buildingsListWidget->count()<=1)
  215         return;
  216     int i=buildingsListWidget->currentRow();
  217     if(i<0 || i>=buildingsListWidget->count())
  218         return;
  219     if(i==buildingsListWidget->count()-1)
  220         return;
  221         
  222     QString s1=buildingsListWidget->item(i)->text();
  223     QString s2=buildingsListWidget->item(i+1)->text();
  224     
  225     Building* bu1=gt.rules.buildingsList.at(i);
  226     Building* bu2=gt.rules.buildingsList.at(i+1);
  227     
  228     gt.rules.internalStructureComputed=false;
  229     setRulesModifiedAndOtherThings(&gt.rules);
  230     
  231     teachers_schedule_ready=false;
  232     students_schedule_ready=false;
  233     rooms_schedule_ready=false;
  234 
  235     buildingsListWidget->item(i)->setText(s2);
  236     buildingsListWidget->item(i+1)->setText(s1);
  237     
  238     gt.rules.buildingsList[i]=bu2;
  239     gt.rules.buildingsList[i+1]=bu1;
  240     
  241     //Begin bug fix on 2017-08-29
  242     Building* vb1=visibleBuildingsList[i];
  243     Building* vb2=visibleBuildingsList[i+1];
  244     visibleBuildingsList[i]=vb2;
  245     visibleBuildingsList[i+1]=vb1;
  246     //End bug fix
  247     
  248     buildingsListWidget->setCurrentRow(i+1);
  249     buildingChanged(i+1);
  250 }
  251 
  252 void BuildingsForm::sortBuildings()
  253 {
  254     gt.rules.sortBuildingsAlphabetically();
  255 
  256     filterChanged();
  257 }
  258 
  259 void BuildingsForm::modifyBuilding()
  260 {
  261     int valv=buildingsListWidget->verticalScrollBar()->value();
  262     int valh=buildingsListWidget->horizontalScrollBar()->value();
  263 
  264     int ci=buildingsListWidget->currentRow();
  265     if(ci<0){
  266         QMessageBox::information(this, tr("FET information"), tr("Invalid selected building"));
  267         return;
  268     }
  269     
  270     Building* bu=visibleBuildingsList.at(ci);
  271     ModifyBuildingForm form(this, bu->name);
  272     setParentAndOtherThings(&form, this);
  273     form.exec();
  274 
  275     filterChanged();
  276     
  277     buildingsListWidget->verticalScrollBar()->setValue(valv);
  278     buildingsListWidget->horizontalScrollBar()->setValue(valh);
  279 
  280     if(ci>=buildingsListWidget->count())
  281         ci=buildingsListWidget->count()-1;
  282 
  283     if(ci>=0)
  284         buildingsListWidget->setCurrentRow(ci);
  285 }
  286 
  287 void BuildingsForm::comments()
  288 {
  289     int ind=buildingsListWidget->currentRow();
  290     if(ind<0){
  291         QMessageBox::information(this, tr("FET information"), tr("Invalid selected building"));
  292         return;
  293     }
  294     
  295     Building* bu=gt.rules.buildingsList[ind];
  296     assert(bu!=NULL);
  297 
  298     QDialog getCommentsDialog(this);
  299     
  300     getCommentsDialog.setWindowTitle(tr("Building comments"));
  301     
  302     QPushButton* okPB=new QPushButton(tr("OK"));
  303     okPB->setDefault(true);
  304     QPushButton* cancelPB=new QPushButton(tr("Cancel"));
  305     
  306     connect(okPB, SIGNAL(clicked()), &getCommentsDialog, SLOT(accept()));
  307     connect(cancelPB, SIGNAL(clicked()), &getCommentsDialog, SLOT(reject()));
  308 
  309     QHBoxLayout* hl=new QHBoxLayout();
  310     hl->addStretch();
  311     hl->addWidget(okPB);
  312     hl->addWidget(cancelPB);
  313     
  314     QVBoxLayout* vl=new QVBoxLayout();
  315     
  316     QPlainTextEdit* commentsPT=new QPlainTextEdit();
  317     commentsPT->setPlainText(bu->comments);
  318     commentsPT->selectAll();
  319     commentsPT->setFocus();
  320     
  321     vl->addWidget(commentsPT);
  322     vl->addLayout(hl);
  323     
  324     getCommentsDialog.setLayout(vl);
  325     
  326     const QString settingsName=QString("BuildingsCommentsDialog");
  327     
  328     getCommentsDialog.resize(500, 320);
  329     centerWidgetOnScreen(&getCommentsDialog);
  330     restoreFETDialogGeometry(&getCommentsDialog, settingsName);
  331     
  332     int t=getCommentsDialog.exec();
  333     saveFETDialogGeometry(&getCommentsDialog, settingsName);
  334     
  335     if(t==QDialog::Accepted){
  336         bu->comments=commentsPT->toPlainText();
  337     
  338         gt.rules.internalStructureComputed=false;
  339         setRulesModifiedAndOtherThings(&gt.rules);
  340 
  341         buildingChanged(ind);
  342     }
  343 }