Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pageitemattributes.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "pageitemattributes.h"
00008 #include "commonstrings.h"
00009 
00010 #include <qstring.h>
00011 #include <qtable.h>
00012 #include <qpushbutton.h>
00013 
00014 PageItemAttributes::PageItemAttributes( QWidget* parent, const char* name, bool modal, WFlags fl )
00015        : PageItemAttributesBase(parent, name, modal, fl)
00016 {
00017        relationships << tr("None", "relationship") << tr("Relates To") << tr("Is Parent Of") << tr("Is Child Of");
00018        relationshipsData << "none" << "relation" << "parent" << "child";
00019 }
00020 
00021 PageItemAttributes::~PageItemAttributes()
00022 {
00023 }
00024 
00025 void PageItemAttributes::setup(ObjAttrVector *pageItemAttrs, ObjAttrVector *docItemAttrs)
00026 {
00027        localAttributes=*pageItemAttrs;
00028        localDocAttributes=*docItemAttrs;
00029 
00030        nameList.clear();
00031        nameList.append("");
00032        for(ObjAttrVector::Iterator it = localDocAttributes.begin(); it!= localDocAttributes.end(); ++it)
00033               nameList.append((*it).name);
00034 
00035        updateTable();
00036 }
00037 
00038 ObjAttrVector* PageItemAttributes::getNewAttributes()
00039 {
00040        return &localAttributes;
00041 }
00042 
00043 
00044 void PageItemAttributes::tableItemChanged( int row, int col )
00045 {
00046        switch (col)
00047        {
00048               case 0:
00049                      localAttributes[row].name=attributesTable->text(row, col);
00050                      break;
00051               case 1:
00052                      localAttributes[row].type=attributesTable->text(row, col);
00053                      break;
00054               case 2:
00055                      localAttributes[row].value=attributesTable->text(row, col);
00056                      break;
00057               case 3:
00058                      localAttributes[row].parameter=attributesTable->text(row, col);
00059                      break;
00060               case 4:
00061               {
00062                      QComboTableItem* qcti=dynamic_cast<QComboTableItem*>(attributesTable->item(row,col));
00063                      if (qcti!=NULL)
00064                      {
00065                             uint index=qcti->currentItem();
00066                             if (index<relationshipsData.count())
00067                                    localAttributes[row].relationship=relationshipsData[index];
00068                      }
00069               }
00070               break;
00071               case 5:
00072                      localAttributes[row].relationshipto=attributesTable->text(row, col);
00073                      break;
00074               case 6:
00075                      //AutoAddTo is not used once this gets to the page items
00076                      /*
00077                      {
00078                             QComboTableItem* qcti=dynamic_cast<QComboTableItem*>(attributesTable->item(row,col));
00079                             if (qcti!=NULL)
00080                             {
00081                                    uint index=qcti->currentItem();
00082                                    if (index<autoAddToData.count())
00083                                           localAttributes[row].autoaddto=autoAddToData[index];
00084                             }
00085                      }
00086                      */
00087                      break;
00088               default:
00089                      break;
00090        }
00091 }
00092 
00093 
00094 void PageItemAttributes::addEntry()
00095 {
00096        ObjectAttribute blank;
00097        blank.name="";
00098        blank.relationship=CommonStrings::None;
00099        blank.autoaddto="none";
00100        localAttributes.append(blank);
00101        updateTable();
00102 }
00103 
00104 
00105 void PageItemAttributes::deleteEntry()
00106 {
00107        int currRow=attributesTable->currentRow();
00108        bool found=false;
00109        ObjAttrVector::Iterator it;
00110        int count=0;
00111        for(it = localAttributes.begin(); it!= localAttributes.end(); ++it)
00112        {
00113               if(count==currRow)
00114               {
00115                      found=true;
00116                      break;
00117               }
00118               ++count;
00119        }
00120        if (found)
00121        {
00122               localAttributes.erase(it);
00123               updateTable();
00124        }
00125 }
00126 
00127 
00128 void PageItemAttributes::clearEntries()
00129 {
00130        localAttributes.clear();
00131        updateTable();
00132 }
00133 
00134 
00135 void PageItemAttributes::copyEntry()
00136 {
00137        int currRow=attributesTable->currentRow();
00138        bool found=false;
00139        ObjAttrVector::Iterator it;
00140        int count=0;
00141        for(it = localAttributes.begin(); it!= localAttributes.end(); ++it)
00142        {
00143               if(count==currRow)
00144               {
00145                      found=true;
00146                      break;
00147               }
00148               ++count;
00149        }
00150        if (found)
00151        {
00152               localAttributes.append((*it));
00153               updateTable();
00154        }
00155 }
00156 
00157 
00158 void PageItemAttributes::updateTable()
00159 {
00160        attributesTable->setNumRows(localAttributes.count());
00161        int row=0;
00162        for(ObjAttrVector::Iterator it = localAttributes.begin(); it!= localAttributes.end(); ++it)
00163        {
00164               uint i=0;
00165               //Name
00166               QComboTableItem *item1 = new QComboTableItem(attributesTable, nameList, true);
00167               if (nameList.contains((*it).name))
00168                      item1->setCurrentItem((*it).name);
00169               else
00170                      item1->setCurrentItem("");
00171               attributesTable->setItem(row, i++, item1);
00172               //Type
00173               QTableItem *item2 = new QTableItem(attributesTable, QTableItem::WhenCurrent, (*it).type);
00174               attributesTable->setItem(row, i++, item2);
00175               //Default Value
00176               QTableItem *item3 = new QTableItem(attributesTable, QTableItem::WhenCurrent, (*it).value);
00177               attributesTable->setItem(row, i++, item3);
00178               //Default Parameter
00179               QTableItem *item4 = new QTableItem(attributesTable, QTableItem::WhenCurrent, (*it).parameter);
00180               attributesTable->setItem(row, i++, item4);
00181               //Relationship
00182               QComboTableItem *item5 = new QComboTableItem(attributesTable, relationships);
00183               attributesTable->setItem(row, i++, item5);
00184               int index=relationshipsData.findIndex((*it).relationship);
00185               if (index==-1)
00186               {
00187                      (*it).relationship="none";
00188                      index=0;
00189               }
00190               item5->setCurrentItem(index);
00191               //Relationship to
00192               QTableItem *item6 = new QTableItem(attributesTable, QTableItem::WhenCurrent, (*it).relationshipto);
00193               attributesTable->setItem(row, i++, item6);
00194               //Auto Add to not used here
00195               /*
00196               QComboTableItem *item7 = new QComboTableItem(attributesTable, autoAddTo);
00197               attributesTable->setItem(row, i++, item7);
00198               index=autoAddToData.findIndex((*it).autoaddto);
00199               if (index==-1)
00200               {
00201                      (*it).autoaddto="none";
00202                      index=0;
00203               }
00204               item7->setCurrentItem(index);
00205               */
00206 
00207               attributesTable->verticalHeader()->setLabel(row, QString("%1").arg(row));
00208               row++;
00209        }
00210        deleteButton->setEnabled(localAttributes.count()!=0);
00211        copyButton->setEnabled(localAttributes.count()!=0);
00212        clearButton->setEnabled(localAttributes.count()!=0);
00213 }
00214 
00215 
00216 void PageItemAttributes::okClicked()
00217 {
00218        //Qt hack as we will lose data if the user hasnt left a cell
00219        //http://www.qtforum.org/thread.php?threadid=9078
00220        if (attributesTable->numRows()>0 && attributesTable->currentRow()!=-1)
00221        {
00222               //Avoid selecting 0,0 if 0,0 is current cell
00223               int selectCol;
00224               if(attributesTable->currentColumn()!=0)
00225                      selectCol=0;
00226               else
00227                      selectCol=1;
00228 
00229               attributesTable->setCurrentCell(0,selectCol);
00230               tableItemChanged(attributesTable->currentRow(), attributesTable->currentColumn());
00231        }
00232        accept();
00233 }
00234 
00235 void PageItemAttributes::languageChange()
00236 {
00237 }
00238 
00239 #include "pageitemattributes.moc"