Back to index

scribus-ng  1.3.4.dfsg+svn20071115
docitemattrprefs.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 "docitemattrprefs.h"
00008 #include "docitemattrprefs.moc"
00009 
00010 #include <qstring.h>
00011 #include <qtable.h>
00012 #include <qpushbutton.h>
00013 
00014 DocumentItemAttributes::DocumentItemAttributes(  QWidget* parent, const char* name, WFlags fl  )
00015        : DocumentItemAttributesBase(parent, name, 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        autoAddTo << tr("None", "auto add") << tr("Text Frames") << tr("Image Frames");
00020        autoAddToData << "none" << "textframes" << "imageframes";
00021        types << tr("None", "types") << tr("Boolean") << tr("Integer") << tr("Real Number") << tr("String");
00022        typesData << "none" << "boolean" << "integer" << "double" << "string";
00023 }
00024 
00025 DocumentItemAttributes::~DocumentItemAttributes()
00026 {
00027 }
00028 
00029 void DocumentItemAttributes::setup(ObjAttrVector *docItemAttrs)
00030 {
00031        localAttributes=*docItemAttrs;
00032        updateTable();
00033 }
00034 
00035 ObjAttrVector* DocumentItemAttributes::getNewAttributes()
00036 {
00037        return &localAttributes;
00038 }
00039 
00040 
00041 void DocumentItemAttributes::tableItemChanged( int row, int col )
00042 {
00043        switch (col)
00044        {
00045        case 0:
00046               localAttributes[row].name=attributesTable->text(row, col);
00047               break;
00048        case 1:
00049               {
00050                      QComboTableItem* qcti=dynamic_cast<QComboTableItem*>(attributesTable->item(row,col));
00051                      if (qcti!=NULL)
00052                      {
00053                             uint index=qcti->currentItem();
00054                             if (index<typesData.count())
00055                                    localAttributes[row].type=typesData[index];
00056                      }
00057               }
00058               break;
00059        case 2:
00060               localAttributes[row].value=attributesTable->text(row, col);
00061               break;
00062        case 3:
00063               localAttributes[row].parameter=attributesTable->text(row, col);
00064               break;
00065        case 4:
00066               {
00067                      QComboTableItem* qcti=dynamic_cast<QComboTableItem*>(attributesTable->item(row,col));
00068                      if (qcti!=NULL)
00069                      {
00070                             uint index=qcti->currentItem();
00071                             if (index<relationshipsData.count())
00072                                    localAttributes[row].relationship=relationshipsData[index];
00073                      }
00074               }
00075               break;
00076        case 5:
00077               localAttributes[row].relationshipto=attributesTable->text(row, col);
00078               break;
00079        case 6:
00080               {
00081                      QComboTableItem* qcti=dynamic_cast<QComboTableItem*>(attributesTable->item(row,col));
00082                      if (qcti!=NULL)
00083                      {
00084                             uint index=qcti->currentItem();
00085                             if (index<autoAddToData.count())
00086                                    localAttributes[row].autoaddto=autoAddToData[index];
00087                      }
00088               }
00089               break;
00090        default:
00091               break;
00092        }
00093 }
00094 
00095 
00096 void DocumentItemAttributes::addEntry()
00097 {
00098        ObjectAttribute blank;
00099        blank.relationship="none";
00100        blank.autoaddto="none";
00101        blank.type="none";
00102        localAttributes.append(blank);
00103        updateTable();
00104 }
00105 
00106 
00107 void DocumentItemAttributes::updateTable()
00108 {
00109        attributesTable->setNumRows(localAttributes.count());
00110        int row=0;
00111        for(ObjAttrVector::Iterator it = localAttributes.begin(); it!= localAttributes.end(); ++it)
00112        {
00113               uint i=0;
00114               //Name
00115               QTableItem *item1 = new QTableItem(attributesTable, QTableItem::WhenCurrent, (*it).name);
00116               attributesTable->setItem(row, i++, item1);
00117               //Type
00118               QComboTableItem *item2 = new QComboTableItem(attributesTable, types);
00119               attributesTable->setItem(row, i++, item2);
00120               int index=typesData.findIndex((*it).type);
00121               if (index==-1)
00122               {
00123                      (*it).type="none";
00124                      index=0;
00125               }
00126               item2->setCurrentItem(index);
00127               //Default Value
00128               QTableItem *item3 = new QTableItem(attributesTable, QTableItem::WhenCurrent, (*it).value);
00129               attributesTable->setItem(row, i++, item3);
00130               //Default Parameter
00131               QTableItem *item4 = new QTableItem(attributesTable, QTableItem::WhenCurrent, (*it).parameter);
00132               attributesTable->setItem(row, i++, item4);
00133               //Relationship
00134               QComboTableItem *item5 = new QComboTableItem(attributesTable, relationships);
00135               attributesTable->setItem(row, i++, item5);
00136               index=relationshipsData.findIndex((*it).relationship);
00137               if (index==-1)
00138               {
00139                      (*it).relationship="none";
00140                      index=0;
00141               }
00142               item5->setCurrentItem(index);
00143               //Relationship to
00144               QTableItem *item6 = new QTableItem(attributesTable, QTableItem::WhenCurrent, (*it).relationshipto);
00145               attributesTable->setItem(row, i++, item6);
00146               //Auto Add to
00147               QComboTableItem *item7 = new QComboTableItem(attributesTable, autoAddTo);
00148               attributesTable->setItem(row, i++, item7);
00149               index=autoAddToData.findIndex((*it).autoaddto);
00150               if (index==-1)
00151               {
00152                      (*it).autoaddto="none";
00153                      index=0;
00154               }
00155               item7->setCurrentItem(index);
00156 
00157               attributesTable->verticalHeader()->setLabel(row, QString("%1").arg(row));
00158               row++;
00159        }
00160        deleteButton->setEnabled(localAttributes.count()!=0);
00161        copyButton->setEnabled(localAttributes.count()!=0);
00162        clearButton->setEnabled(localAttributes.count()!=0);
00163 }
00164 
00165 
00166 void DocumentItemAttributes::deleteEntry()
00167 {
00168        int currRow=attributesTable->currentRow();
00169        bool found=false;
00170        ObjAttrVector::Iterator it;
00171        int count=0;
00172        for(it = localAttributes.begin(); it!= localAttributes.end(); ++it)
00173        {
00174               if(count==currRow)
00175               {
00176                      found=true;
00177                      break;
00178               }
00179               ++count;
00180        }
00181        if (found)
00182        {
00183               localAttributes.erase(it);
00184               updateTable();
00185        }
00186 }
00187 
00188 
00189 void DocumentItemAttributes::clearEntries()
00190 {
00191        localAttributes.clear();
00192        updateTable();
00193 }
00194 
00195 
00196 void DocumentItemAttributes::copyEntry()
00197 {
00198        int currRow=attributesTable->currentRow();
00199        bool found=false;
00200        ObjAttrVector::Iterator it;
00201        int count=0;
00202        for(it = localAttributes.begin(); it!= localAttributes.end(); ++it)
00203        {
00204               if(count==currRow)
00205               {
00206                      found=true;
00207                      break;
00208               }
00209               ++count;
00210        }
00211        if (found)
00212        {
00213               localAttributes.append((*it));
00214               updateTable();
00215        }
00216 }
00217 
00218 QStringList DocumentItemAttributes::getDocAttributesNames()
00219 {
00220        QStringList nameList;
00221        for(ObjAttrVector::Iterator it = localAttributes.begin(); it!= localAttributes.end(); ++it)
00222               nameList.append((*it).name);
00223        return nameList;
00224 }