Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Name_Abbrev_Root_dlg.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Graeme Foster                                   *
00003  *   email    foster.graeme@gmail.com                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include "Name_Abbrev_Root_dlg.h"
00021 #include <iostream>
00022 
00023 #define SPACE 8
00024 #define MARGIN 6
00025 
00026 NameAbbrevRootDlg::NameAbbrevRootDlg(int nameWidth
00027                                     ,QString nameLabel
00028                                     ,int abbrevWidth
00029                                     ,QString abbrevLabel
00030                                     ,QMainWindow *parent)
00031         : RootDlg()
00032 {
00033         // The status bar must be set up here because RootDlg is a virtual parent
00034         statusBar = parent->statusBar();
00035         na_wdgt = new NameAbbrevWidget(nameWidth
00036                                       ,nameLabel
00037                                       ,abbrevWidth
00038                                       ,abbrevLabel
00039                                       ,ui.frame
00040                                       ,ui.vboxLayout2
00041                                       ,this
00042                                       );
00043 }
00044 
00045 bool NameAbbrevRootDlg::enableBtn(QString oldName
00046                                  ,QString oldAbbrev
00047                                  ,int parentID
00048                                  ,RootItem * rootItem
00049                                  ,bool (*pUniqueName)(QString, int)
00050                                  ,bool (*pUniqueAbbrev)(QString, int))
00051 {
00052         return enableBtn(oldName
00053                         ,getName()
00054                         ,oldAbbrev
00055                         ,getAbbrev()
00056                         ,parentID
00057                         ,rootItem
00058                         ,pUniqueName
00059                         ,pUniqueAbbrev
00060                         ,this
00061                         );
00062 }
00063 bool NameAbbrevRootDlg::enableBtn(QString oldName
00064                                       ,QString newName
00065                                       ,QString oldAbbrev
00066                                       ,QString newAbbrev
00067                                       ,int parentID
00068                                       ,RootItem * rootItem
00069                                       ,bool (*pUniqueName)(QString, int)
00070                                       ,bool (*pUniqueAbbrev)(QString, int)
00071                                       ,RootDlg * dialog
00072                                       )
00073 {
00074         if(newName.isEmpty() || newAbbrev.isEmpty())
00075         {
00076                 dialog->okButtonEnabled(false);
00077                 return false;
00078         }
00079         
00080         if (rootItem != 0) // existing object
00081         {
00082                 if (oldName == newName
00083                 && oldAbbrev == newAbbrev )
00084                 {
00085                         dialog->okButtonEnabled(false);
00086                         return false;
00087                 }
00088                 else
00089                 {
00090                         if(oldName != newName && !pUniqueName(newName,parentID) )
00091                         {
00092                                 dialog->okButtonEnabled(false);
00093                                 return false;
00094                         }
00095                         else
00096                                 if(oldAbbrev != newAbbrev && !pUniqueAbbrev(newAbbrev, parentID))
00097                                 {
00098                                         dialog->okButtonEnabled(false);
00099                                         return false;
00100                                 }
00101                                 else
00102                                 {
00103                                         dialog->okButtonEnabled(true);
00104                                         return true;
00105                                 }
00106                 }
00107         }
00108         else // new object
00109         {
00110                 if (pUniqueAbbrev(newAbbrev, parentID)
00111                         && pUniqueName(newName, parentID))
00112                 {
00113                         dialog->okButtonEnabled(true);
00114                         return true;
00115                 }
00116                 else
00117                 {
00118                         dialog->okButtonEnabled(false);
00119                         return false;
00120                 }
00121         }
00122         return true;
00123 }

Generated on Thu Apr 6 16:27:16 2006 for time-table by  doxygen 1.4.4